| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/nsu_controller_helper.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/nsu_log.class.php';
- class DBARRAPIInvoice extends DolibarrApi
- {
- public $nsuControllerHelper = new NsuControllerHelper();
- /**
- * Invoice/draft
- *
- * @param array $cart //product ID => darabszám
- * @param boolean $invoice // Invoice / Receipt
- *
- *
- * @return array|mixed Data without useless information
- *
- * @url POST draft
- */
- public function draft(array $cart, boolean $invoice = false, int $billing_id = null)
- {
- $array = [];
- $log_id = ApiNSULog::getLogId();
- ApiNSULog::invoiceLog("{$log_id}: DBARRAPIInvoice->draft");
- $dbTransactionID = $this->nsuControllerHelper->generateTransactionID($log_id);
- $lines = $this->nsuControllerHelper->getProductLines($product_id);
- $apiInvoiceHelper = new ApiInvoiceHelper;
- $invoiceObj = $apiInvoiceHelper->createInvoice($invoice, $log_id, $company_invoice);
- ApiNSULog::invoiceLog("{$log_id} Invoice created");
- $products = [];
- foreach ($lines as $line) {
- $invoiceObj = $apiInvoiceHelper->addLineToInvoice($invoiceObj, $line, $log_id);
- $product = $apiInvoiceHelper->loadProductToResult($line);
- if (!empty($product)) {
- $products[] = $product;
- }
- }
- $invoiceObj->fetch_lines();
- foreach ($products as &$row) {
- foreach ($invoiceObj->lines as $line) {
- if ($line->product_ref == $row['ref']) {
- $row['price'] = $line->multicurrency_total_ttc;
- $row['total_tva'] = $line->total_tva;
- }
- }
- }
- return $array;
- }
- /**
- * Invoice/createInvoice
- *
- * @param string $dolibar_transaction_id //Dolibarr transaction id
- * @param string $simple_transaction_id //Simple Pay transaction id
- * @param array $payment //Payment array
- * @param array $invoice //Invoice array
- * @param string $log_id //logId
- *
- *
- *
- * @return array|mixed Data without useless information
- *
- * @url POST createInvoice
- */
- public function createInvoice(string $dolibar_transaction_id, string $simple_transaction_id, array $payment, array $invoice, string $log_id)
- {
- $array = [];
- $apiInvoiceHelper = new ApiInvoiceHelper;
- $invoiceObj = []
- $invoiceObj = $apiInvoiceHelper->validateInvoice($invoiceObj, $log_id);
- /**
- * set payment
- */
- $apiInvoiceHelper->setPayment($invoiceObj, $payment, $log_id);
- /**
- * save card payment data
- */
- if (!empty($cardPaymentLog)) {
- $invoiceObj = $apiInvoiceHelper->saveCardPaymentLog($invoiceObj, $cardPaymentLog, $log_id);
- }
- ApiBbusLog::appLog("{$log_id} Invoice created. ID: {$invoiceObj->id} REF: {$invoiceObj->ref} REQ: {$log_id}");
- dol_syslog("{$log_id} Invoice created. ID: {$invoiceObj->id} REF: {$invoiceObj->ref} REQ: {$log_id}", LOG_INFO, 0);
- //$bbApiLock->delete($user);
- ApiBbusLog::appLog("{$log_id}####################################################################");
- dol_syslog("{$log_id}####################################################################", LOG_INFO, 0);
- $products = [];
- return [
- 'log_id' => $log_id,
- 'invoice' => [
- 'id' => $invoiceObj->id,
- 'ref' => $invoiceObj->ref,
- 'total' => $invoiceObj->multicurrency_total_ttc
- ],
- 'products' => $products,
- ];
- return $array;
- }
- /**
- * Invoice/list
- *
- * @param int $backenduser_id //ID of the backenduser
- * @return array|mixed Data without useless information
- *
- * @url GET list
- */
- public function list($backenduser_id)
- {
- $array = [];
- $sql = "SELECT * FROM llx_facture as f INNER JOIN llx_facture_extrafields as fe ON fe.fk_facture = f.rowid WHERE fe.backenduser_id = {$backenduser_id}";
- $array = $this->nsuControllerHelper->getObject($sql);
- return $array;
- }
- /**
- * Invoice/details
- *
- * @param int $facture_id //Facture rowid
- *
- *
- * @return array|mixed Data without useless information
- *
- * @url GET details
- */
- public function deatils(int $facture_id)
- {
- global $db;
- $factureObj = new Facture($db);
- $result = $factureObj->fetch($facture_id);
- if($db->num_rows($result) > 0){
- return $factureObj;
- }
- return [];
- }
- /**
- * Invoice/resend
- *
- * @param int $facture_id //Facture rowid
- *
- *
- * @return array|mixed Data without useless information
- *
- * @url GET resend
- */
- public function resend(int $facture_id)
- {
- $array = [];
- $note = "";
- $this->nsuControllerHelper->emailSender($note, $array);
- }
- }
- class DBARRAPIBilling extends DolibarrApi
- {
- public $nsuControllerHelper = new NsuControllerHelper();
- /**
- * billing/create
- *
- * @param string $name
- * @param string $city
- * @param int $zip
- * @param string $town
- * @param int $currency
- * @param string $currencyCode
- *
- * @return array|mixed Data without useless information
- *
- * @url POST create
- */
- public function create(string $name, string $city, int $zip, string $town, int $currency, string $currencyCode)
- {
- $array = [];
- global $db, $user;
- $ThirdPartyObj = new Societe($db);
- $ThirdPartyObj->nom = $name;
- $ThirdPartyObj->entity = 1;
- $ThirdPartyObj->address = $city;
- $ThirdPartyObj->zip = $zip;
- $ThirdPartyObj->town = $town;
- $ThirdPartyObj->fk_multicurrency = $currency;
- $ThirdPartyObj->multicurrency_code = $currencyCode;
- $result = $ThirdPartyObj->create($user);
- if($result){
- return $ThirdPartyObj; # Megnézni, hogy mivel tér vissza és mit kell visszaadni.
- }
- return $array;
- }
- /**
- * billing/modify
- *
- * @param int $thirdpartyID
- * @param string $name
- * @param string $city
- * @param int $zip
- * @param string $town
- * @param int $currency
- * @param string $currencyCode
- *
- * @return array|mixed Data without useless information
- *
- * @url POST modify
- */
- public function modify(int $thirdpartyID, string $name, string $city, int $zip, string $town, int $currency, string $currencyCode)
- {
- $array = [];
- global $db, $user;
- $ThirdParty = new Societe($db);
- $result = $ThirdPartyObj->fetch($thirdpartyID);
- $ThirdPartyObj->nom = $name;
- $ThirdPartyObj->entity = 1;
- $ThirdPartyObj->address = $city;
- $ThirdPartyObj->zip = $zip;
- $ThirdPartyObj->town = $town;
- $ThirdPartyObj->fk_multicurrency = $currency;
- $ThirdPartyObj->multicurrency_code = $currencyCode;
- $result = $ThirdPartyObj->update($user);
- if($result){
- return $ThirdPartyObj; # Megnézni, hogy mivel tér vissza és mit kell visszaadni.
- }
- return $array;
- }
- /**
- * billing/delete
- *
- * @param int $thirdpartyID
- * @param string $name
- * @param string $city
- * @param int $zip
- * @param string $town
- * @param int $currency
- * @param string $currencyCode
- *
- * @return array|mixed Data without useless information
- *
- * @url POST delete
- */
- public function delete(int $thirdpartyID)
- {
- global $db, $user;
- $ThirdParty = new Societe($db);
- $result = $ThirdPartyObj->delete($thirdpartyID);
- if($result){
- return true; # Megnézni, hogy mivel tér vissza és mit kell visszaadni.
- }
- return false;
- }
- }
- class DBARRAPIFacilities extends DolibarrApi
- {
- public $nsuControllerHelper = new NsuControllerHelper();
- /**
- * ticket/list
- *
- * @return array|mixed Data without useless information
- *
- * @url GET list
- */
- public function list()
- {
- $array = [];
- return $array;
- }
- /**
- * ticket/details
- *
- * @param int $facility_id //facility ID
- *
- * @return array|mixed Data without useless information
- *
- * @url GET details
- */
- public function details(int $facility_id)
- {
- $array = [];
- return $array;
- }
- }
- class DBARRAPITicket extends DolibarrApi
- {
- public $nsuControllerHelper = new NsuControllerHelper();
- /**
- * ticket/details
- *
- * @param int $ticket_id //ticket rowid
- * @param int $backend_user_id //backend_user_id
- *
- *
- * @return array|mixed Data without useless information
- *
- * @url GET details
- */
- public function details(int $ticket_id, int $backend_user_id)
- {
- $array = [];
- global $db;
- $NSUTIcketObj = new NSUTicket($db);
- $result = $NSUTIcketObj->fetch($ticket_id);
- if($db->num_rows($result) > 0){
- return $NSUTIcketObj;
- }
- return $array;
- }
- /**
- * ticket/tickets
- *
- * @param int $backenduser_id //backend_user_id
- *
- *
- * @return array|mixed Data without useless information
- *
- * @url GET tickets
- */
- public function tickets(int $backenduser_id)
- {
- $array = [];
- $facturesArray = DBARRAPIInvoice::list($backenduser_id);
- if(!empty($facturesArray)){
- $tmp_factures_array = [];
- foreach($facturesArray as $facture){
- $tmp_factures_array[] = $facture['rowid'];
- }
- $factures = implode(',', $tmp_factures_array);
- $sql = "SELECT * FROM llx_nsu_ticket as t WHERE t.fk_facture IN ({$factures})";
- $array = $this->nsuControllerHelper->getObject($sql);
- }
-
- return $array;
- }
- }
|