Finished Cpeshipping

This commit is contained in:
Frank Schubert
2021-10-28 20:53:27 +02:00
parent 877d511030
commit 5a9ffd2679
11 changed files with 425 additions and 17 deletions

View File

@@ -196,7 +196,7 @@
<div class="col-md-1">
<div class="form-group">
<label class="form-label" for="wifi_pass-<?=$product->id?>">WLAN Passwort</label>
<label class="form-label" for="wifi_pass-<?=$product->id?>">WPA Key</label>
<input class="form-control" type="text" name="wifi_pass" id="router_wifi_pass-<?=$product->id?>" value="<?=$product->cpeprovisioning->wifi_pass?>" />
</div>
</div>

View File

@@ -0,0 +1,126 @@
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
<li class="breadcrumb-item"><a href="<?=self::getUrl("Cpeshipping")?>">CPE Versand</a></li>
<li class="breadcrumb-item active">Versand-CSV History</li>
</ol>
</div>
<h4 class="page-title">CPE Versand</h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<a class="btn btn-warning" href="<?=self::getUrl("Cpeshipping")?>">Zurück zu CPE-Versand</a>
</div>
</div>
<div class="card">
<div class="card-body mb-3">
<h4 class="header-title">Versand-CSVs</h4>
<?php if($pagination['maxItems'] > $pagination['count']): ?>
<nav>
<ul class="pagination justify-content-center mb-1">
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
</li>
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
</li>
<?php for($i = 0; $i < ($pagination['maxItems'] / $pagination['count']); $i++): ?>
<li class="page-item <?=($pagination['start'] == $i*$pagination['count']) ? "disabled font-weight-bold" : ""?>"><a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $i*$pagination['count'], "filter" => $filter])?>"><?=$i+1?></a></li>
<?php endfor; ?>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Vor</a>
</li>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
</li>
</ul>
</nav>
<?php endif; ?>
<div class="pagination justify-content-center">
<?php if($pagination['maxItems']): ?>
Versand-CSVs <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
<?php else: ?>
Keine Versand-CSVs gefunden
<?php endif; ?>
</div>
<table class="table table-striped table-hover">
<tr>
<th>Dateiname</th>
<th>Name</th>
<th>Versandt von</th>
</tr>
<?php foreach($shippings as $s): ?>
<tr>
<td><a href="<?=self::getUrl("File", "download", ["id" => $s->file_id])?>"><?=$s->file->filename?></a></td>
<td><?=$s->file->name?></td>
<td><?=$s->creator->name?></td>
</tr>
<?php endforeach; ?>
</table>
<?php if($pagination['maxItems'] > $pagination['count']): ?>
<nav>
<ul class="pagination justify-content-center mb-1">
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
</li>
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
</li>
<?php for($i = 0; $i < ($pagination['maxItems'] / $pagination['count']); $i++): ?>
<li class="page-item <?=($pagination['start'] == $i*$pagination['count']) ? "disabled font-weight-bold" : ""?>"><a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $i*$pagination['count'], "filter" => $filter])?>"><?=$i+1?></a></li>
<?php endfor; ?>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Vor</a>
</li>
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
</li>
</ul>
</nav>
<?php endif; ?>
<div class="pagination justify-content-center">
<?php if($pagination['maxItems']): ?>
Versand-CSVs <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
<?php else: ?>
Keine Versand-CSVs gefunden
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
var download_id;
var hash = window.location.hash.substr(1);
var match = hash.match(/download=(\d+)/);
if(match && match[1]) {
download_id = match[1]
console.log("<?=self::getUrl("File", "download")?>?id=" + download_id);
window.location.href="<?=self::getUrl("File", "download")?>?id=" + download_id;
window.location.hash = "";
}
});
</script>
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>

View File

@@ -58,30 +58,31 @@
<?php endif; ?>
</div>
<form method="post" action="<?=self::getUrl("Cpeshipping", "ship")?>">
<form method="post" id="submit-form" action="<?=self::getUrl("Cpeshipping", "ship")?>">
<table class="table table-striped table-hover">
<tr>
<th class="text-center">Versand<br /><input type="checkbox" id="checkAll" class="form-control" /></th>
<th class="text-center">Externes Produkt<br />bestellt</th>
<th>Kundennummer</th>
<th>Kunde</th>
<th>Lieferort</th>
<th>Gerät</th>
<th>Lieferort</th>
<th>Kunde</th>
<th>Kundennummer</th>
</tr>
<?php foreach($cpeprovisionings as $c): ?>
<tr>
<td class="versand-checkbox text-center"><input type="checkbox" class="form-control" name="ships[]" value="<?=$c->id?>" /></td>
<td class="versand-checkbox text-center"><input type="checkbox" class="form-control" id="ship-<?=$c->id?>" name="ships[]" value="<?=$c->id?>" /></td>
<td class="text-center">
<?php if(array_key_exists("hostnetwork_order", $c->orderproduct->product->attributes) && $c->orderproduct->product->attributes['hostnetwork_order']->value): ?>
<input type="checkbox" class="form-control" name="external_finish-<?=$c->id?>" value="1" />
<input type="checkbox" class="form-control" id="external_finish-<?=$c->id?>" name="external_finish-<?=$c->id?>" value="1" />
<span id="ship-error-<?=$c->id?>" class="text-danger hidden">Externes Produkt muss bestellt sein vor Versand!</span>
<?php else: ?>
n/a
<?php endif; ?>
</td>
<td><?=$c->order->owner->customer_number?></td>
<td><?=$c->order->owner->getCompanyOrName()?></td>
<td><?=($c->termination_id) ? $c->termination->building->zip." ".$c->termination->building->city : $c->order->owner->zip." ".$c->order->owner->city?></td>
<td><?=$c->routertype?></td>
<td><?=($c->termination_id) ? $c->termination->building->zip." ".$c->termination->building->city : $c->order->owner->zip." ".$c->order->owner->city?></td>
<td><?=$c->order->owner->getCompanyOrName()?></td>
<td><?=$c->order->owner->customer_number?></td>
</tr>
<?php endforeach; ?>
</table>
@@ -134,5 +135,33 @@
$('.versand-checkbox input:checkbox').not(this).prop('checked', this.checked);
});
});
$("#submit-form" ).submit(function( event ) {
$('[id^=ship-error-').each(function() {
$(this).hide();
});
var error = false;
$('input[name^=external_finish-]').each(function() {
var id_match = $(this).attr("name").match(/external_finish-(\d+)$/);
var id = id_match[1];
if(!$("input[name^=external_finish-").is(":checked")) {
if($("#ship-" + id).is(":checked")) {
error = true;
$("#ship-error-" + id).show();
}
}
});
if(error) {
console.log("not submitting");
event.preventDefault();
}
return;
});
</script>
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>

View File

@@ -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();
@@ -73,11 +100,51 @@ class CpeshippingController extends mfBaseController {
$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);
}
}

View File

@@ -0,0 +1,39 @@
<?php
class CpeshippingFile extends mfBaseModel {
private $file;
private $creator;
private $editor;
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}

View File

@@ -0,0 +1,141 @@
<?php
class CpeshippingFileModel {
public $file_id;
public $create_by = null;
public $edit_by = null;
public $create = null;
public $edit = null;
private static $SqlOptions = ["orderBy" => "id"];
public static function create(Array $data) {
$model = new CpeshippingFile();
foreach($data as $field => $value) {
if(property_exists(get_called_class(), $field)) {
$model ->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getOne($id) {
if(!is_numeric($id) || !$id) {
throw new Exception("Invalid number", 400);
}
$item = [];
$db = FronkDB::singleton();
$res = $db->select("CpeshippingFile", "*", "id=$id LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new CpeshippingFile($data);
}
return $item;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("CpeshippingFile", "*", "$where ORDER BY id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new CpeshippingFile($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("CpeshippingFile", "*", "1=1 ORDER BY id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new CpeshippingFile($data);
}
}
return $items;
}
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM CpeshippingFile WHERE $where";
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sqlOptions = self::$SqlOptions;
if(array_key_exists("SqlOptions", $filter) && is_array($filter['SqlOptions']) && count($filter['SqlOptions'])) {
if(array_key_exists("orderBy", $filter['SqlOptions'])) {
$SqlOptions["orderBy"] = $filter['SqlOptions']['orderBy'];
}
}
$sql = "SELECT * FROM CpeshippingFile WHERE $where ORDER BY ".$SqlOptions["orderBy"];
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
$sql .= " LIMIT ".$limit['count'];
}
}
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new CpeshippingFile($data);
}
}
return $items;
}
private function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("file_id", $filter)) {
$file_id = $filter['file_id'];
if(is_numeric($file_id)) {
$where .= " AND file_id=$file_id";
}
}
return $where;
}
}

View File

@@ -4,8 +4,10 @@ class File extends mfBaseModel {
private $creator;
private $editor;
public function createFile($overwrite = false) {
// TODO
public static function createFile($filename = false, $overwrite = false) {
// make filename
}
public function delete() {

View File

@@ -26,9 +26,10 @@ class FileController extends mfBaseController {
throw new Exception("File not found", 404);
}
$filename = $file->store_filename;
$path = MFUPLOAD_FILE_SAVE_PATH."/documents/$filename";
$path = MFUPLOAD_FILE_SAVE_PATH;
$path .= ($file->subfolder) ? "/".$file->subfolder : "";
$path .= "/$filename";
//var_dump($path);exit;
if(!file_exists($path)) {
throw new Exception("File not found", 4041);
}

View File

@@ -280,6 +280,7 @@ class LineworkController extends mfBaseController {
$file_data = [];
$file_data['name'] = ($r->file_name) ? $r->file_name : $upload->getOriginalFilename();
$file_data['filename'] = ($r->file_filename) ? $r->file_filename : $upload->getOriginalFilename();
$file_data['subfolder'] = "documents";
$file_data['store_filename'] = $upload->getFilename();
$file_data['orig_filename'] = $upload->getOriginalFilename();

View File

@@ -618,6 +618,7 @@ class OrderController extends mfBaseController {
$file_data = [];
$file_data['name'] = ($r->file_name) ? $r->file_name : $upload->getOriginalFilename();
$file_data['filename'] = ($r->file_filename) ? $r->file_filename : $upload->getOriginalFilename();
$file_data['subfolder'] = "documents";
$file_data['store_filename'] = $upload->getFilename();
$file_data['orig_filename'] = $upload->getOriginalFilename();

View File

@@ -269,6 +269,7 @@ class PipeworkController extends mfBaseController {
$file_data = [];
$file_data['name'] = ($r->file_name) ? $r->file_name : $upload->getOriginalFilename();
$file_data['filename'] = ($r->file_filename) ? $r->file_filename : $upload->getOriginalFilename();
$file_data['subfolder'] = "documents";
$file_data['store_filename'] = $upload->getFilename();
$file_data['orig_filename'] = $upload->getOriginalFilename();