���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /var/www/dev-kft.petruch.de/classes/order.class.php
���ѧ٧ѧ�
<?php class Order{ private $sql = false; public $path = 'files/order/'; private $user = false; private $mailer = false; function __construct() { global $sql; $this->sql = $sql; global $user; $this->user = $user; global $mailer; $this->mailer = $mailer; } /***************** * STATUS * 1: Neu / Erstellt => Von Endkunden gekommen * 7: Neu / Erstellt => von Backend gekommen * 5: Angenommen -> Nur relevant falls Auftrag direkt von Kunden kommt * 6: Abgelehnt -> Nur relevant falls Auftrag direkt von Kunden kommt * * 10: Zur Produktion Freigegeben * 13: Wareneingangskontrolle * 15: Auftrag in Produktion * * 20: Auftrag pausiert * * 30: Auftrag on Hold * 31: Auftrag on Hold -> Warten auf Material * 32: Auftrag on Hold -> Warten auf Maschine * 33: Auftrag on Hold -> Zu viele Falschteile produziert! * * 80: Storniert * 98: Auftrag erfolgreich abgeschlossen -> muss noch abgenommen werden * 99: Auftrag erfolgreich abgeschlossen * * REIHENFOLGE: * Wird über 'sort' in order festgelegt pro Maschine * Sortierung ist ASC -> 0 ist zuerst * Sortierung wirkt sich nur auf Aufträge aus, die den Status 10 haben. * * ABLAUF Auftrag kommt von Kockzius: * 0 -> 10 * Um einen Auftrag freizugeben, kann er als "nächstes", als "letztes" oder an einer bestimmten Position freigegeben werden. * Beginnt ein Tablet die Arbeit, wird geprüft, ob ein Auftrag auf 20 gesetzt ist, wenn ja, wird er auf 15 gesetzt -> Auftrag in Produktion * Falls kein Auftrag mit 20 vorhanden ist, wird der erste Auftrag aus der Liste mit 10 auf 15 gesetzt. -> Auftrag in Produktion * Pausiert ein Mitarbeiter einen Auftrag (Schichtwechsel oder Tag beendet), wird der Status auf 20 gesetzt. * Falls ein Auftrag vor erst nicht weitergemacht werden kann (Warten auf Material, Maschine oder Mitarbeiter), wird der Status auf 30 gesetzt. -> Auftrag on Hold -> Ggf. Kunden informieren * Dann wird wieder mit 10 weitergemacht. * Um einen Auftrag aus dem Status 30 zu holen, muss der Status auf 10 gesetzt werden und ggf. neu priorisiert werden. -> Zur Produktion Freigegeben * Ist ein Auftrag abgeschlossen, wird der Status entweder auf 98 oder auf 99 gesetzt und sort wird auf 0 gesetzt. * 98 wenn der Auftrag noch abgenommen werden muss -> das hängt von Kundeneinstellung "approveOrder" ab -> wird in Funktion finishOrder im Tablet gesetzt. * 99 wenn der Auftrag abgeschlossen ist ohne Kundenprüfung. * 95 wenn der Auftrag nicht angenommen wurde, sondern reklamiert wurde * * ABLAUF Auftrag kommt von Kunde: * 0 -> 5 * Wird ein Auftrag von einem Kunden erstellt, wird der Status auf 5 gesetzt. -> Angenommen -> Kunde wird benachrichtigt * Wird der Auftrag abgelehnt, wird der Status auf 6 gesetzt. -> Abgelehnt -> Kunde wird benachrichtigt inkl. Freitext-Info und kann Auftrag neu erstellen. * Wird der Auftrag angenommen, kann der Status auf 10 gesetzt werden. -> Zur Produktion Freigegeben * Rest wie oben * * incomingGoodsInspection: * 0: Nicht geprüft * 1: Geprüft und bestanden * 2: Geprüft und nicht bestanden * 5: Nicht geprüft, aber übersprungen ******************/ public function getStatusName($status,$incomingGoodsInspection = false){ if(!$incomingGoodsInspection && $status < 21 && $status > 7) return 'Wareneingangskontrolle'; switch($status){ case 1: return 'Neu v. Kunde'; // von Kunden case 7: return 'Neu'; // vom Backend case 5: return 'Angenommen'; // Gibt es nicht -> Ist immer Status 10 case 6: return 'Abgelehnt'; case 10: return 'Freigabe Produktion'; case 13: return 'Wareneingangskontrolle'; case 15: return 'In Produktion'; case 20: return 'Auftrag pausiert'; case 30: case 31: case 32: case 33: return 'On Hold'; case 80: return 'Storniert'; case 95: return 'Reklamation'; case 98: return 'Warte auf Kundenabnahme'; case 99: return 'Abgeschlossen'; default: return 'Unbekannt'; } } /** * Add Order * @param object $p * @return boolean */ public function add($p) { if($this->checkCustomerOrderNr($p->customerOrderNr,$p->customerID)) return false; $color = generateLightColor(); $hash = $this->getHash(); $p->machineID = 0; $status = 7; $sort = 9; $approveOrder = $this->sql->select('approveOrder', 'customer', 'id=?', $p->customerID, 1); return $this->sql->insert('orders', 'approveOrder,customerID,machineID,productID,toolingID,customerOrderNr,hash,amountTarget,briefing,status,color,sort,created,changed', [$approveOrder, $p->customerID,$p->machineID,$p->productID,$p->toolingID,$p->customerOrderNr,$hash,$p->amountTarget,$p->briefing,$status,$color,$sort,NOW, NOW]); } /** * Check if customerOrderNr already exists * @param integer $customerOrderNr * @return integer */ public function checkCustomerOrderNr($customerOrderNr,$customerID){ return $this->sql->select('id', 'orders', 'customerOrderNr=? AND customerID = ?', [$customerOrderNr,$customerID], 1); } /** * Get Tablet Hash */ public function getHash() { $hash = createHash(12); if($this->sql->select('id', 'orders', 'hash=?', $hash, 1)) return $this->getHash(); return $hash; } /** * Delete Order * @param int $orderID * @return boolean */ public function delete($p) { return $this->sql->update('orders', 'status', 80, 'id=?', [$p->orderID]); } /** * Change Status * @param object $p * @return boolean */ public function changeStatus($p) { if(isset($p->resetIncomingGoodsInspection) && $p->resetIncomingGoodsInspection) $this->resetIncomingGoodsInspection($p); $oldStatus = $this->sql->select('status', 'orders', 'id=?', $p->orderID, 1); if($oldStatus == "1"){ $order = $this->getOrder($p->orderID); $customerLogin = $this->getCustomerLoginDetails($order->customerLoginID); if($p->status == 10 && $customerLogin){ $body = 'Hallo '.$customerLogin->firstName.' '.$customerLogin->name.',<br /> <br /> wir haben Ihren Auftrag '.$order->customerOrderNr.' angenommen und zur Produktion freigegeben.<br /> Über diese Link können Sie Ihren Auftrag abrufen: <a href="https://kunde.kockzius.de/auftrage/'.$order->hash.'/">Auftrag öffnen</a><br /><br /> Mit freundlichen Grüßen<br /> Ihr Kockzius-Team'; $this->mailer->myMail($customerLogin->email, 'Ihr Auftrag '.$order->customerOrderNr.' wurde angenommen', $body); }elseif($p->status == 6 && $customerLogin){ $this->sql->insert('order_declined','orderID,userID,request,info',[ $p->orderID, $this->user->id, 'order.new', $p->info]); $body = 'Hallo '.$customerLogin->firstName.' '.$customerLogin->name.',<br /> <br /> leider konnten wir Ihren Auftrag '.$order->customerOrderNr.' nicht annehmen:<br /> '.nl2br($p->info).'<br /><br /> Bitte prüfen Sie den Auftrag und erstellen Sie diesen erneut.<br /> Über diese Link können Sie Ihren Auftrag abrufen: <a href="https://kunde.kockzius.de/auftrage/'.$order->hash.'/">Auftrag öffnen</a><br /><br /> Mit freundlichen Grüßen<br /> Ihr Kockzius-Team'; $this->mailer->myMail($customerLogin->email, 'Ihr Auftrag '.$order->customerOrderNr.' wurde abgelehnt', $body); } } return $this->sql->update('orders', 'currentTaskID,status,changed', [0,$p->status,NOW], 'id=?', $p->orderID); } /** * Reset Incoming Goods Inspection * @param object $p * @return boolean */ public function resetIncomingGoodsInspection($p) { return $this->sql->update('orders', 'incomingGoodsInspection,incomingGoodsInspectionDate,changed', [0,0,NOW], 'id=?', $p->orderID); } /** * Reset Incoming Goods Inspection * @param object $p * @return boolean */ public function skipIncomingGoodsInspection($p) { // TODO: Needs furhter development -> see tablet!! return $this->sql->update('orders', 'incomingGoodsInspection,incomingGoodsInspectionDate,changed', [5,NOW,NOW], 'id=?', $p->orderID); } /** * Change Order * @param object $p * @return boolean */ public function change($p) { return $this->sql->update('orders', 'customerID,machineID,productID,toolingID,customerOrderNr,amountTarget,briefing,status,color,changed', [$p->customerID,$p->machineID,$p->productID,$p->toolingID,$p->customerOrderNr,$p->amountTarget,$p->briefing,$p->status,$p->color,NOW], 'id=?', $p->orderID); } /** Change Prio of order * @param object $p * @return boolean */ public function changePrio($p) { return $this->sql->update('orders', 'sort,changed', [$p->sort,NOW], 'hash=?', $p->hash); } /** * Start Order * @param object $p * @return boolean */ public function start($p){ return $this->sql->update('orders', 'machineID,briefing,sort,status,changed', [$p->machineID,$p->briefing,$p->sort,10,NOW], 'id=?', $p->orderID); } /** * Get Order ID by Hash * @param object $hash * @return int */ public function getOrderIDbyHash($hash){ return $this->sql->select('id', 'orders', 'hash=?', $hash, 1); } /** * Get ToDo for Dashboard by Status * @param int $status * @return string */ public function getOrderToDo($status, $deviationReportPrinted){ if($status === 1) return 'Auftrag freigeben'; if($status >= 30 && $status <= 33) return 'Auftrag prüfen'; if($status > 90 && !$deviationReportPrinted) return 'Abweichungsbericht drucken'; } /** * Get Order * @param int $orderID * @param boolean $noMachine * @return object */ public function getOrder($orderID,$noMachine=false){ if($noMachine){ $select = 'o.customerLoginID, o.approveOrder, o.deviationReportPrinted,o.hash,o.id,o.customerID,o.productID,o.toolingID,o.customerOrderNr,o.amountTarget,o.amountFinished,o.briefing,o.status,o.color,o.sort,o.created,o.changed,o.incomingGoodsInspection,o.incomingGoodsInspectionDate,DATE_FORMAT(o.dateFinished,"%d.%m.%Y") AS dateFinishedShow,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow, CONCAT(c.firstName," ",c.name) AS customerUserName,p.name AS productNameShow, p.batchSize, p.exactBatchSize, t.name AS toolingNameShow, "" AS machineNameShow'; $tbl = 'orders o, customer c, product p, tooling t'; $where = 'o.id=? AND c.id = o.customerID AND p.id = o.productID AND t.id = o.toolingID'; }else{ $select = 'o.customerLoginID, o.approveOrder, o.deviationReportPrinted,o.hash,o.id,o.customerID,o.machineID,o.productID,o.toolingID,o.customerOrderNr,o.amountTarget,o.amountFinished,o.briefing,o.status,o.color,o.sort,o.created,o.changed,o.incomingGoodsInspection,o.incomingGoodsInspectionDate,DATE_FORMAT(o.dateFinished,"%d.%m.%Y") AS dateFinishedShow,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow, CONCAT(c.firstName," ",c.name) AS customerUserName,m.name AS machineNameShow, p.name AS productNameShow, p.batchSize, p.exactBatchSize, t.name AS toolingNameShow'; $tbl = 'orders o, customer c, machine m, product p, tooling t'; $where = 'o.id=? AND c.id = o.customerID AND m.id = o.machineID AND p.id = o.productID AND t.id = o.toolingID'; } $order = $this->sql->select($select, $tbl, $where, $orderID, 1); $order->amountBadPart = 0; $order->amountGoodPart = 0; $order->part = $this->sql->select('p.userID,p.badpartID,p.amount,p.info,p.sessionID,b.reportingAmount,b.name,p.created,b.sort','order_part p, product_badpart b','b.id = p.badpartID AND p.orderID=? AND p.productID=? ORDER BY p.created ASC',[$order->id,$order->productID]); if($order->part){ foreach($order->part AS $part){ if($part->badpartID) $order->amountBadPart += $part->amount; else $order->amountGoodPart += $part->amount; } $badpartSum = array_reduce($order->part, function($accumulator, $item) { if (!isset($accumulator[$item->badpartID])) { $accumulator[$item->badpartID] = (object) ['reportingAmount' => $item->reportingAmount,'badpartID' => $item->badpartID, 'name' => $item->name, 'totalAmount' => 0, 'sort' => $item->sort, 'alert' => false]; } $accumulator[$item->badpartID]->totalAmount += $item->amount; if($accumulator[$item->badpartID]->totalAmount >= $accumulator[$item->badpartID]->reportingAmount) $accumulator[$item->badpartID]->alert = true; else $accumulator[$item->badpartID]->alert = false; return $accumulator; }, []); sort($badpartSum); $order->badpartSum = $badpartSum; } $order->task = $this->sql->select('o.taskID,o.amount,o.info,o.sessionID, DATE_FORMAT(o.created,"%d.%m.%Y") AS createdDateShow, DATE_FORMAT(o.created,"%H:%i") AS createdTimeShow, o.created, t.name AS taskName, t.nextTaskID, u.name as userName, u.firstName AS userFirstName','orders_task o, task t, user u','o.orderID=? AND t.id = o.taskID AND u.id = o.userID ORDER BY o.created DESC',$order->id); $order->sessionAmount = $this->countUniqueSessionIDs($order->task); $order->statusName = $this->getStatusName($order->status,$order->incomingGoodsInspection); $order->amountWithdrawal = $this->sql->select('SUM(w.amount) AS amount, u.firstName, u.name','order_withdrawal w, user u','u.id = w.userID AND w.orderID=? AND w.productID=? GROUP BY w.userID',[$order->id,$order->productID]); $order->deviationReports = $this->sql->select('id,DATE_FORMAT(created,"%d.%m.%Y") as batchFinishedDate,DATE_FORMAT(created,"%H:%i") as batchFinishedTime,amount','order_part','orderID=? AND batchFinished=1',$order->id); $order->orderReports = $this->sql->select('id,DATE_FORMAT(created,"%d.%m.%Y") as batchFinishedDate,DATE_FORMAT(created,"%H:%i") as batchFinishedTime','order_part','orderID=? AND orderFinished=1',$order->id,1); $order->customerRequests = $this->sql->select('id,orderID,request,info,sort','order_customer_request','accepted=0 AND declined=0 AND orderID=?',$order->id); return $order; } private function countUniqueSessionIDs($array) { if(!is_array($array)) return 0; $sessionIDs = array_map(function($element) { return $element->sessionID; }, $array); $uniqueSessionIDs = array_unique($sessionIDs); return count($uniqueSessionIDs); } /** * Count Parts betweend two dates * @param array $parts * @param string $begin * @param string $end * @return object */ public function countPartsByCreated($parts, $begin, $end){ $r = false; if($parts){ foreach($parts AS $part){ if($part->created >= $begin && $part->created <= $end && $part->amount){ if(!$r){ $r = new stdClass; $r->amount = 0; $r->badParts = 0; $r->goodParts = 0; } $r->amount += $part->amount; if($part->badpartID) $r->badParts += $part->amount; else $r->goodParts += $part->amount; $badpartSum = array_reduce($parts, function($accumulator, $item) { if (!isset($accumulator[$item->badpartID])) { $accumulator[$item->badpartID] = (object) ['reportingAmount' => $item->reportingAmount,'badpartID' => $item->badpartID, 'name' => $item->name, 'totalAmount' => 0, 'alert' => false]; } $accumulator[$item->badpartID]->totalAmount += $item->amount; if($accumulator[$item->badpartID]->totalAmount >= $accumulator[$item->badpartID]->reportingAmount) $accumulator[$item->badpartID]->alert = true; else $accumulator[$item->badpartID]->alert = false; return $accumulator; }, []); sort($badpartSum); $r->badparts = $badpartSum; } } } return $r; } /** * Set Timestamp when DeviationReport was pritned for the first time * @param int $orderID * @return boolean */ public function changeDeviationReportPrinted($orderID){ return $this->sql->update('orders','deviationReportPrinted,deviationReportPrintedDate',[1,NOW],'id=?',$orderID); } public function getRequests(){ $orderIDs = $this->sql->select('orderID,request,info,sort','order_customer_request','accepted=0 AND declined=0'); if(!$orderIDs) return false; $r = []; foreach($orderIDs AS $orderID){ $order = $this->getOrder($orderID->orderID); $order->request = $this->requestToText($orderID->request); $order->info = $orderID->info; $order->sort = $orderID->sort; $r[] = $order; } return $r; } public function requestToText($request){ if($request == 'order.storno') return 'Stornierungsanfrage'; if($request == 'order.sort') return 'Priorisierungänderungssanfrage'; if($request == 'order.complain') return 'Reklamation'; } public function customerRequestHandle($p){ if($p->decision == 'accepted'){ $this->sql->update('order_customer_request','accepted,acceptedDate',[1,NOW],'id=?',$p->requestID); if($p->request == 'order.storno'){ $p->status = 80; return $this->changeStatus($p); } if($p->request == 'order.complain'){ $p->status = 99; return $this->changeStatus($p); } if($p->request == 'order.sort'){ return $this->changePrio($p); } }elseif($p->decision == 'declined'){ $order = $this->getOrder($p->orderID); $customerLoginID = $this->getCustomerLoginID($p->requestID); $customerLogin = $this->getCustomerLoginDetails($customerLoginID); $this->sql->update('order_customer_request','declined,declinedDate',[1,NOW],'id=?',$p->requestID); $body = 'Hallo '.$customerLogin->firstName.' '.$customerLogin->name.',<br /> <br /> leider konnten wir Ihre '.$this->requestToText($p->request).' zum Auftrag '.$order->customerOrderNr.' nicht annehmen:<br /> '.nl2br($p->info).'<br /><br /> Über diese Link können Sie Ihren Auftrag abrufen: <a href="https://kunde.kockzius.de/auftrage/'.$order->hash.'/">Auftrag öffnen</a><br /><br /> Mit freundlichen Grüßen<br /> Ihr Kockzius-Team'; $this->mailer->myMail($customerLogin->email, $this->requestToText($p->request).' zum Auftrag '.$order->customerOrderNr, $body); if($p->request == 'order.complain'){ $p->status = 98; return $this->changeStatus($p); } return $this->sql->insert('order_declined','orderID,userID,requestID,request,info',[$p->orderID, $this->user->id, $p->requestID, $p->request, $p->info]); } } private function getCustomerLoginDetails($customerLoginID){ return $this->sql->select('email,firstName,name','customer_login','id=?',$customerLoginID,1); } private function getCustomerLoginID($requestID){ return $this->sql->select('customerLoginID','order_customer_request','id=?',$requestID,1); } /** * Get all Orders * @return array | boolean */ public function getAll($_status,$hasDeviationReport=false,$limit=false,$sort=false) { if(!is_array($_status)) $_status = [$_status]; $select = 'o.dateFinished,o.deviationReportPrinted, o.incomingGoodsInspection,o.hash,o.id,o.customerID,o.machineID,o.productID,o.customerOrderNr,o.amountTarget,o.amountFinished,o.briefing,o.status,o.color,o.sort,o.created,o.changed,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow, m.name AS machineNameShow, p.name AS productNameShow, t.name AS toolingNameShow'; $tbl = 'orders o, customer c, machine m, product p, tooling t'; $where = 'o.status=? AND c.id = o.customerID AND m.id = o.machineID AND p.id = o.productID AND t.id = o.toolingID'; $selectNoMachine = 'o.dateFinished,o.deviationReportPrinted,o.incomingGoodsInspection,o.hash,o.id,o.customerID,o.productID,o.customerOrderNr,o.amountTarget,o.amountFinished,o.briefing,o.status,o.color,o.sort,o.created,o.changed,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow, p.name AS productNameShow, "" AS machineNameShow, "" AS toolingNameShow'; $tblNoMachine = 'orders o, customer c, product p'; $whereNoMachine = 'o.status=? AND c.id = o.customerID AND p.id = o.productID'; $r = []; foreach($_status AS $status){ if(in_array($status, [0])){ $h = $this->sql->select($selectNoMachine, $tblNoMachine,$whereNoMachine.' ORDER BY o.sort ASC, o.created ASC',[$status]); if($h) array_unshift($r, $h); } elseif(in_array($status, [1,2,5,6])){ $h = $this->sql->select($select, $tbl,$where.' ORDER BY o.sort ASC, o.created ASC',[$status]); if($h) $r[] = $h; } elseif(in_array($status, [10])){ $h = $this->sql->select($select, $tbl,$where.' AND incomingGoodsInspection > 0 ORDER BY o.sort ASC, o.created ASC',[$status]); if($h) $r[] = $h; } elseif(in_array($status, [15,20])){ $h = $this->sql->select($select, $tbl,$where.' AND incomingGoodsInspection > 0 ORDER BY o.dateStarted ASC',[$status]); if($h) $r[] = $h; } elseif(in_array($status, [30,31,32,33])){ $h = $this->sql->select($select, $tbl,$where.' AND incomingGoodsInspection > 0 ORDER BY o.created ASC',[$status]); if($h) $r[] = $h; }elseif(in_array($status, [95,98,99]) && $hasDeviationReport){ $h = $this->sql->select($select, $tbl,$where.' AND deviationReportPrinted = 0 ORDER BY o.created DESC',[$status]); if($h) $r[] = $h; }elseif(in_array($status, [80,95,98,99])){ $h = $this->sql->select($select, $tbl,$where.' ORDER BY o.dateFinished DESC',[$status]); if($h) $r[] = $h; } else{ $h = $this->sql->select($select, $tbl,$where.' AND incomingGoodsInspection > 0 ORDER BY o.dateFinished DESC',[$status]); if($h) $r[] = $h; } } if(empty($r)) return false; $result = array_reduce($r, function ($carry, $item) { return array_merge($carry, $item); }, []); if($sort){ usort($result, function($a, $b) { if ($a->dateFinished == $b->dateFinished) { return ($a->created < $b->created) ? 1 : -1; } return ($a->dateFinished < $b->dateFinished) ? 1 : -1; }); } if($limit){ $result = array_slice($result, 0, $limit); } return ($result); } /** * Get all Orders without Incoming Goods Inspection * @return array | boolean */ public function getAllNoIncomingGoodsInspection(){ $select = 'o.incomingGoodsInspection,o.hash,o.id,o.customerID,o.machineID,o.productID,o.customerOrderNr,o.amountTarget,o.amountFinished,o.briefing,o.status,o.color,o.sort,o.created,o.changed,IF(c.company != "",c.company,CONCAT(c.firstName," ",c.name)) AS customerNameShow, p.name AS productNameShow, DATE_FORMAT(o.created,"%d.%m.%Y") AS createDateShow'; $tbl = 'orders o, customer c, product p'; $where = 'o.incomingGoodsInspection=0 AND status >= 7 AND status <= 20 AND c.id = o.customerID AND p.id = o.productID'; $r = $this->sql->select($select, $tbl.' WHERE '.$where.' ORDER BY o.sort ASC, o.created ASC'); if(empty($r)) return false; return ($r); } public function searchOrder($q){ $select = 'o.incomingGoodsInspection, o.hash, o.id, o.customerID, o.machineID, o.productID, o.customerOrderNr, o.amountTarget, o.amountFinished, o.briefing, o.status, o.color, o.sort, o.created, o.changed, m.name AS machineNameShow, t.name AS toolingNameShow, IF(c.company != "", c.company, CONCAT(c.firstName, " ", c.name)) AS customerNameShow, p.name AS productNameShow, DATE_FORMAT(o.created, "%d.%m.%Y") AS createDateShow'; $tbl = 'orders o LEFT JOIN customer c ON c.id = o.customerID LEFT JOIN product p ON p.id = o.productID LEFT JOIN machine m ON m.id = o.machineID LEFT JOIN tooling t ON t.id = o.toolingID'; $where = '(o.customerOrderNr LIKE ? OR p.name LIKE ? OR c.company LIKE ? OR CONCAT(c.firstName, " ", c.name) LIKE ?)'; $return = $this->sql->select($select, $tbl,$where.' ORDER BY o.sort ASC, o.created ASC',['%'.$q.'%','%'.$q.'%','%'.$q.'%','%'.$q.'%']); if(!$return) $return = []; $i = 0; foreach($return AS $r){ $return[$i]->statusName = $this->getStatusName($r->status,$r->incomingGoodsInspection); $return[$i]->name = showOrderName($r); $i++; } return ($return); } /** * Print Deviation Report (Abweichungsbericht) * @param object $p * @param boolean $showBrowser * @return boolean */ public function printDeviationReport($p,$showBrowser=false){ $orderID = $this->getOrderIDbyHash($p->hash); if(!$orderID){ return false; } $order = $this->getOrder($orderID); $path = 'files/reports/'.$p->hash.'/'; if(!is_dir(DIR.$path)) mkdir(DIR.$path, 0777, true); $filename = showOrderName($order).'-abweichungsbericht.pdf'; if($p->reportCount){ $filename = showOrderName($order).'-bericht-kiste-'.$p->reportCount.'.pdf'; } $amountTables = $this->getAmountTablePDF($order,$p->reportCount); $date = $order->dateFinishedShow; $creator = ''; foreach($order->task AS $task){ if($task->taskID == 9){ $creator = $task->userFirstName.' '.$task->userName; } } $html = '<!DOCTYPE html> <html> <head> <link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap" rel="stylesheet"> <style> *{ font-family: "Ubuntu"; font-size: 20px; } h1,h2,h3,h4,strong{ font-weight: 700; } .wp100{ width: 100%; } h1, h2{ font-size: 24px; } @page { margin: 20px 80px 20px; } .ta-right{ text-align: right; } header{ position: fixed; top: 0px; left: 0px; right: 0px; color: #999; } main{ margin-top: 50px; page-break-after: always; } footer{ width: 100%; position: fixed; height: 0; bottom: 30px; left: 0; right: 0; color: #999; font-size: 10px; } table{ width: 100%; margin: 0; td{ width: 40%; text-align: left; } td.b{ width: 60%; border: 2px solid #000; padding: 10px; } } </style> </head> <title>Abweichungsbericht '.showOrderName($order).'</title> <body> <header style="text-align: right;"> <img src="'.HOST.'/assets/logo/logo-dark.png" style="width: 200px;" /> </header>'; foreach($amountTables AS $amountTable){ $html .= '<main class="all"> <h2>Abweichungsbericht</h2> <table> <tr> <td>Kunde:</td> <td class="b">'.$order->customerNameShow.'</td> </tr> <tr> <td>Auftragsnummer:</td> <td class="b">'.showOrderName($order).'</td> </tr> <tr> <td>Datum:</td> <td class="b">'.$date.'</td> </tr> <tr> <td>Artikel:</td> <td class="b">'.$order->productNameShow.'</td> </tr> </table> <h2 style="margin-top: 50px;">Stückzahlen</h2> '.$amountTable.' <table style="margin-top: 50px;"> <tr> <td>Name des Erstellers:</td> <td class="b">'.$creator.'</td> </tr> </table> </main>'; } $html .= '</body> </html>'; $fontDirectory = '/var/www/html/kft/assets/fonts'; //change to the diretory where you fonts is located on your server $options = new Dompdf\Options(); $options->set('enable_php',true); $options->set('isRemoteEnabled', true); $options->set('isHtml5ParserEnabled', true); $options->setIsRemoteEnabled(true); $options->setChroot($fontDirectory); $dompdf = new Dompdf\Dompdf($options); $dompdf->getFontMetrics()->registerFont( ['family' => 'Ubuntu', 'style' => 'normal', 'weight' => 'normal'], $fontDirectory . '/ubuntu-v20-latin-regular.ttf' ); $dompdf->getFontMetrics()->registerFont( ['family' => 'Ubuntu', 'style' => 'normal', 'weight' => 'bold'], $fontDirectory . '/ubuntu-v20-latin-700.ttf' ); $dompdf->loadHtml($html); $dompdf->render(); $output = $dompdf->output(); if(!$order->deviationReportPrinted){ $this->changeDeviationReportPrinted($orderID); } if($showBrowser){ echo $dompdf->stream($output, ["Attachment" => false]); exit(0); } file_put_contents(DIR.$path.$filename, $output); return HOST.'/'.$path.$filename.'?'.filemtime(DIR.$path.$filename); } private function getAmountTablePDF($order,$reportCount,$countPages=0,$badpartIDs=[]){ $newBadpartIDs = []; $amountTable = ''; $goodParts = 0; if(!$reportCount){ // Display all in one Table: $amountTable .= '<table> <tr> <td>Gute Teile:</td> <td class="b">'.$order->amountGoodPart.' St.</td> </tr>'; foreach($order->badpartSum AS $badpart){ if($badpart->badpartID) $amountTable .= '<tr> <td>'.$badpart->name.':</td> <td class="b">'.$badpart->totalAmount.' St.</td> </tr>'; } $amountTable .= '<tr> <td>Summe:</td> <td class="b">'.($order->amountGoodPart + $order->amountBadPart).' St.</td> </tr> </table>'; }else{ $taskCounter = 0; $reportCounter = 1; $prevBatch = '0000-00-00'; $reportCount++; $date = $order->dateFinishedShow; $amountTable = '<table>'; if($order->exactBatchSize && !$badpartIDs){ $goodParts = $order->batchSize > 0 ? $order->amountGoodPart % $order->batchSize : $order->amountGoodPart; $amountTable .= '<tr> <td>Gute Teile:</td> <td class="b">'.$goodParts.' St.</td> </tr>'; }else{ foreach($order->task AS $task){ // Good Parts if the batchSize is not exact -> uses the times when the batch was created if(($task->taskID == 8 || $task->taskID == 9) && $parts = $this->countPartsByCreated($order->part, $prevBatch, $task->created)){ if($reportCount == $reportCounter){ $amountTable .= '<tr> <td>Gute Teile:</td> <td class="b">'.$parts->goodParts.' St.</td> </tr>'; $goodParts = $parts->goodParts; $date = $task->createdDateShow.', '.$task->createdTimeShow.' Uhr'; } $prevBatch = $task->created; $reportCounter++; } $taskCounter++; } } // Is not batchsize is defined in product -> the batchSize is always the amount of good parts + bad parts if(!$order->batchSize){ $order->batchSize = $order->amountBadPart + $goodParts; } usort($order->badpartSum, function($a, $b) { return $b->sort - $a->sort; }); $actualBatchSize = $goodParts; if($order->badpartSum){ foreach($order->badpartSum AS $badpart){ if(!$badpart->badpartID || $badpart->badpartID === 1) continue; $foundKey = array_search($badpart->badpartID, array_column($badpartIDs, 'badpartID')); if(!$badpartIDs || $foundKey !== false){ if(!$badpartIDs && $badpart->totalAmount > $order->batchSize){ //Falls mehr als eine Batch an schlechten Teilen vorhanden sind: if($order->batchSize > 0){ $fullBatches = intdiv($badpart->totalAmount, $order->batchSize); $rest = $order->batchSize > 0 ? $badpart->totalAmount % $order->batchSize : $badpart->totalAmount; }else{ $fullBatches = 1; $rest = 0; } for ($i = 0; $i < $fullBatches; $i++) { $newBadpartIDs[] = [ 'badpartID' => $badpart->badpartID, 'amount' => $order->batchSize ]; } if ($rest > 0) { $newBadpartIDs[] = [ 'badpartID' => $badpart->badpartID, 'amount' => $rest ]; } }elseif($foundKey !== false && isset($badpartIDs[$foundKey]["amount"]) && $badpartIDs[$foundKey]["amount"] + $actualBatchSize <= $order->batchSize){ $amountTable .= '<tr> <td>'.$badpart->name.':</td> <td class="b">'.$badpartIDs[$foundKey]["amount"].' St.</td> </tr>'; $actualBatchSize += $badpartIDs[$foundKey]["amount"]; unset($badpartIDs[$foundKey]); }elseif($badpart->totalAmount + $actualBatchSize > $order->batchSize){ // Falls die aktuellen Teile nicht mehr in die Kiste passen: $newBadpartIDs[] = ['badpartID' => $badpart->badpartID, 'amount' => $badpart->totalAmount]; }else{ $amountTable .= '<tr> <td>'.$badpart->name.':</td> <td class="b">'.$badpart->totalAmount.' St.</td> </tr>'; $actualBatchSize += $badpart->totalAmount; } } } } $amountTable .= '<tr> <td>Summe:</td> <td class="b">'.($actualBatchSize).' St.</td> </tr> </table>'; /* Every Abweichungsbericht for each batch: $taskCounter = 0; $reportCounter = 1; $prevBatch = 0; foreach($order->task AS $task){ $nextTask = isset($order->task[$taskCounter+1])?$order->task[$taskCounter+1]:false; if($task->taskID == 8 && $parts = $this->countPartsByCreated($order->part, $prevBatch, $task->created)){ if($p->reportCount == $reportCounter){ $amountTable .= '<table> <tr> <td>Gute Teile:</td> <td class="b">'.$parts->goodParts.' St.</td> </tr>'; foreach($parts->badparts AS $badpart){ if($badpart->badpartID) $amountTable .= '<tr> <td>'.$badpart->name.':</td> <td class="b">'.$badpart->totalAmount.' St.</td> </tr>'; } $amountTable .= '<tr> <td>Summe:</td> <td class="b">'.($parts->goodParts + $parts->badParts).' St.</td> </tr> </table>'; $date = $task->createdDateShow.', '.$task->createdTimeShow.' Uhr'; } $prevBatch = $task->created; $reportCounter++; } $taskCounter++; } */ } $r[] = $amountTable; if($badpartIDs){ $newBadpartIDs = array_values($badpartIDs); } if($newBadpartIDs){ $r = array_merge(array_values($r), array_values($this->getAmountTablePDF($order,$reportCount,($countPages+1),$newBadpartIDs))); } return $r; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0.01 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�