Pārlūkot izejas kodu

multiprinting, bbticket saving fixes

szollosil 1 gadu atpakaļ
vecāks
revīzija
0197acce9b

+ 4 - 3
custom/bbus/class/api_bbus.class.php

@@ -448,7 +448,7 @@ class BBus extends DolibarrApi
 			if ($server_host == $conf->global->LOCAL_SERVER_HOST) {
 				ApiBbusLog::appLog("dateHandler: local");
 				ApiBbusLog::appLog("dateHandler: {$datetime_timestamp}");
-				$this->localDateHandler($ref, $datetime, $datetime_timestamp, $now);
+				$this->localDateHandler($ref, $datetime, $datetime_timestamp, $now, $type_id);
 			} else {
 				ApiBbusLog::appLog("dateHandler: curl");
 				$this->curlDateHandler($ref, $datetime, $type_id);
@@ -467,7 +467,7 @@ class BBus extends DolibarrApi
 		$helper = new ApiBBusHelper();
 		$facture_id = $helper->getFactureIdForInvoicePrinting($ref);
 		if (empty($facture_id)) {
-			ApiBbusLog::appLog("localDateHandler: facture_id because cross-shopping");
+			ApiBbusLog::appLog("localDateHandler: no facture_id because cross-shopping");
 			$printedCopies = $this->checkPrintedCopiesWithRef($ref);
 		} else {
 			$printedCopies = $this->checkPrintedCopies($facture_id);
@@ -489,10 +489,11 @@ class BBus extends DolibarrApi
 				$helper->setPrintingInvoiceObject($user, $facture_id, $datetime, $datetime_timestamp, $ticket, $ref);
 			}
 		} else {
+			ApiBbusLog::appLog("printedCopies: MULTIPRINT");
 			if (empty($facture_id)) {
 				$ticketIds = $helper->getTicketIdsForCrossShopping($ref);
 			} else {
-				$ticketIds = $helper->getTicketIdsByFactureId($facture_id);
+				$ticketIds = $helper->getTicketIdsByFactureId($facture_id, $ref);
 			}
 			$ticketObj = new stdClass();
 			foreach ($ticketIds as $key => $value) {

+ 2 - 1
custom/bbus/class/api_bbus_helper.class.php

@@ -178,11 +178,12 @@ class ApiBBusHelper
 		}
 	}
 
-	public function getTicketIdsByFactureId($facture_id)
+	public function getTicketIdsByFactureId($facture_id, $ref)
 	{
 		$object = new stdClass();
 		$object->fk_facture = $facture_id;
 		$object->fk_product = $this->getproductIdFromFActuredet($facture_id);
+		$object->invoice_number = $ref;
 		$bbTicketHandler = new BbTicketHandler();
 		// uj rekordot veszek fel a bbticket tablaba és visszaterek a rogzitett rekordok roid-javal
 		return $bbTicketHandler->addTicketForPrinting($object);

+ 18 - 1
custom/bbus/class/bbtickethandler.class.php

@@ -109,9 +109,15 @@ class BbTicketHandler
         $ticketIds = [];
         $this->getProductAssociationFils($object);
         $this->getDatecFromFacture($object);
+        $booking_history_id = $this->getBookingHistoryId($object->invoice_number);
 
         foreach ($object->fk_product as $record) {
-            $ticket = $this->createTicketObject($this->pere[0], $record, $object->fk_facture);
+            $GroupUsersObj = new GroupUsers($this->db);
+            $groupUsersResult = $GroupUsersObj->fetchAll('DESC', 'rowid', 1, 0, ['customsql' => "fk_user = {$this->user->id}"]);
+            foreach($groupUsersResult as $group){
+                $group_id = $group->fk_settlements_group;
+            }
+            $ticket = $this->createTicketObject($this->pere[0], $record, $object->fk_facture, $object->invoice_number, $group_id, $booking_history_id);
             $insertedTicket = $ticket->create($this->user);
             if ($insertedTicket == -1) {
                 dol_syslog("Nem sikerult a ticketek mentese. facture_id: " . $object->fk_facture);
@@ -121,6 +127,17 @@ class BbTicketHandler
         return $ticketIds;
     }
 
+    private function getBookingHistoryId($invoice_number){
+        $sql = "SELECT rowid FROM llx_booking_bookinghistory WHERE invoice_number = '{$invoice_number}'";
+        $result = $this->db->query($sql);
+        if($this->db->num_rows($result) > 0){
+            while($row = $this->db->fetch_object($result)){
+                return $row->rowid;
+            }
+        }
+        return null;
+    }
+
     private function getProductAssociationFils($object)
     {
         $arrayForIN = implode(",",$object->fk_product);