Finished Cpeshipping
This commit is contained in:
@@ -38,6 +38,28 @@ class CpeshippingController extends mfBaseController {
|
||||
|
||||
}
|
||||
|
||||
protected function historyAction() {
|
||||
$this->layout()->setTemplate("Cpeshipping/History");
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$ship_search = ["SqlOptions" => ["orderBy" => "id DESC"]];
|
||||
|
||||
$pagination['maxItems'] = CpeshippingFileModel::count($ship_search);
|
||||
$shippings = CpeshippingFileModel::search($ship_search, $pagination);
|
||||
|
||||
$this->layout()->set("shippings", $shippings);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
}
|
||||
|
||||
protected function shipAction() {
|
||||
//$this->redirect("Cpeshipping");
|
||||
$r = $this->request;
|
||||
@@ -48,8 +70,12 @@ class CpeshippingController extends mfBaseController {
|
||||
$ships = $r->ships;
|
||||
}
|
||||
|
||||
$shippings = [];
|
||||
if(!count($ships)) {
|
||||
$this->layout()->setFlash("Keine CPEs ausgewählt", "warning");
|
||||
$this->redirect("Cpeshipping");
|
||||
}
|
||||
|
||||
$shippings = [];
|
||||
foreach($ships as $prov_id) {
|
||||
if(!is_numeric($prov_id) || $prov_id <= 0) {
|
||||
continue;
|
||||
@@ -65,6 +91,7 @@ class CpeshippingController extends mfBaseController {
|
||||
continue;
|
||||
}
|
||||
$shippings[] = $prov;
|
||||
|
||||
}
|
||||
|
||||
$tpl = new Layout();
|
||||
@@ -72,12 +99,52 @@ class CpeshippingController extends mfBaseController {
|
||||
$tpl->set("shippings", $shippings);
|
||||
$tpl->set("me", $this->me);
|
||||
$body = $tpl->render();
|
||||
|
||||
//$values = $tpl->getReturnedValue();
|
||||
|
||||
/*
|
||||
header("Content-type: text/csv");
|
||||
header("Content-disposition: attachment; filename=\"dhl-shipment-".date("Y-m-d-H-i-s").".csv\"");
|
||||
echo $body;exit;
|
||||
*/
|
||||
|
||||
$folder = MFUPLOAD_FILE_SAVE_PATH."/csv";
|
||||
$filename = "dhl-shipment-".date("Y-m-d-H-i-s").".csv";
|
||||
$path = "$folder/$filename";
|
||||
|
||||
if(!file_put_contents($path, $body)) {
|
||||
$this->layout()->setFlash("Fehler beim Erstellen der CSV-Datei", "error");
|
||||
$this->redirect("Cpeshipping");
|
||||
}
|
||||
|
||||
$file = new File();
|
||||
$file->name = "DHL Shipment CSV ".date("d.m.Y H:i:s");
|
||||
$file->filename = $filename;
|
||||
$file->store_filename = $filename;
|
||||
$file->subfolder = "csv";
|
||||
$file->create_by = $this->me->id;
|
||||
$file->edit_by = $this->me->id;
|
||||
$file_id = $file->save();
|
||||
if(!$file_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern der CSV-Datei (File)", "error");
|
||||
$this->redirect("Cpeshipping");
|
||||
}
|
||||
|
||||
$shippingfile = CpeshippingFileModel::create(['file_id' => $file_id]);
|
||||
$shippingfile_id = $shippingfile->save();
|
||||
|
||||
if(!$shippingfile_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern der CSV-Datei (ShippingFile)", "error");
|
||||
$this->redirect("Cpeshipping");
|
||||
}
|
||||
|
||||
foreach($shippings as $prov) {
|
||||
$prov->shipped = 1;
|
||||
$prov->shipped_by = $this->me->id;
|
||||
$prov->cpeshippingfile_id = $shippingfile_id;
|
||||
$prov->save();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Versand-CSV erfolgreich erstellt.", "success");
|
||||
$this->redirect("Cpeshipping", "History", null, "download=".$file_id);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user