Files
b2b.redline.com.pl/modules/firmesb2b/B2BDocument.php
2025-06-27 16:13:26 +02:00

185 lines
5.0 KiB
PHP

<?php
/*
* 2012 Firmes
* Mechanizmy obs³ugi rozszerzenia FirmesLink B2B
* Obsluga wyswietlania historii dokumentow
*/
class B2BDocument extends ObjectModel
{
protected $_taxCalculationMethod = PS_TAX_EXC;
public function __construct($id = NULL, $id_lang = NULL)
{
parent::__construct($id, $id_lang);
}
public static function getCustomerDocumentsCount($id_customer)
{
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(do_documentId) AS count
FROM `yfi_documents`
INNER JOIN `yfi_customerinfo` ON do_payerCustomerId = ci_customerId
WHERE ci_shopCustomerId = '.(int)$id_customer.'');
if (!$res)
return array();
return $res;
}
public static function getCustomerDocuments($id_customer, $limit = 25, $start = 0)
{
global $cookie;
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
do_sourceId AS source_id
, do_documentId AS document_id
, do_fullNumber AS number
, do_date AS date
, do_totalNet AS total_net
, do_totalGros AS total_gros
, do_paymentAmount AS payment_ammount
, do_paymentDate AS payment_date
, DATEDIFF(do_PaymentDate,NOW()) AS payment_lateness
, do_title AS title
, yfi_documents.*
, pdf.*
, epp.db_binaryId AS \'eppid\', epp.db_file AS \'eppfile\'
FROM `yfi_documents`
INNER JOIN `yfi_customerinfo` ON do_payerCustomerId = ci_customerId
LEFT JOIN `yfi_documentbinaries` pdf ON do_documentId = pdf.db_binaryId AND do_sourceId = pdf.db_sourceId
LEFT JOIN `yfi_documentbinaries` epp ON do_documentId = (epp.db_binaryId * -1) AND do_sourceId = epp.db_sourceId
WHERE ci_shopCustomerId = '.(int)$id_customer.'
ORDER BY do_executionDate DESC, do_documentId DESC
LIMIT '.$start.', '.$limit.'');
if (!$res)
return array();
return $res;
}
public static function getCustomerDocumentById($id_customer, $document_id, $source_id = 1, $binary_id = 0)
{
global $cookie;
// Warunek filtrujący pliki epp
$whereSQL = ($binary_id == 0)? '':' AND db_binaryId = '.$binary_id;
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
do_sourceId AS source_id
, do_documentId AS document_id
, do_fullNumber AS number
, do_date AS date
, do_totalNet AS total_net
, do_totalGros AS total_gros
, do_paymentAmount AS payment_ammount
, do_paymentDate AS payment_date
, DATEDIFF(do_PaymentDate,NOW()) AS payment_lateness
, do_title AS title
, yfi_documents.*
, yfi_documentbinaries.*
FROM `yfi_documents`
INNER JOIN `yfi_customerinfo` ON do_payerCustomerId = ci_customerId
LEFT JOIN `yfi_documentbinaries` ON do_documentId = db_documentId AND do_sourceId = db_sourceId
WHERE ci_shopCustomerId = '.(int)$id_customer.' AND do_documentId = '.(int)$document_id .' AND do_sourceId = '.(int)$source_id .''.$whereSQL.'
ORDER BY do_date DESC, do_documentId DESC');
if (!$res)
return array();
return $res[0];
}
public static function getDocumentDetails($document_id, $source_id = 1)
{
global $cookie;
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
di_productName AS product_name
, di_quantity AS quantity
, di_unitOfMeasure AS unit
, di_priceNet AS price_net
, di_priceGros AS price_gros
, di_taxRate AS tax_rate
, di_totalNet AS total_net
, di_totalGros AS total_gros
, di_discount AS discount
, yfi_documentitems.*
FROM `yfi_documentitems`
WHERE di_documentId = '.(int)$document_id .' AND di_sourceId = '.(int)$source_id .'
ORDER BY di_documentItemId DESC');
if (!$res)
return array();
return $res;
}
public static function getRelatedDocuments($document_id, $source_id)
{
global $cookie;
$sql = '
SELECT
bi_sourceId,
bi_binaryId,
bi_objectId,
bi_objectType,
bi_type,
bi_name,
bi_description,
bi_binary,
bi_file,
bi_fromdb,
bi_shopBinaryId,
bi_shopObjectId,
bi_timestamp
FROM `yfi_binaries`
INNER JOIN `yfi_documents` ON bi_objectId = do_documentId AND do_sourceId = bi_sourceId
WHERE do_documentId = '.(int)$document_id.' AND bi_sourceId = '.(int)$source_id.' ORDER BY bi_objectId';
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
if (!$res)
return array();
return $res;
}
public static function getRelatedDocumentById($file_document_id, $source_id)
{
global $cookie;
$sql = '
SELECT
bi_sourceId,
bi_binaryId,
bi_objectId,
bi_objectType,
bi_type,
bi_name,
bi_description,
bi_binary,
bi_file,
bi_fromdb,
bi_shopBinaryId,
bi_shopObjectId,
bi_timestamp
FROM `yfi_binaries`
INNER JOIN `yfi_documents` ON bi_objectId = do_documentId AND do_sourceId = bi_sourceId
WHERE bi_binaryId = '.(int)$file_document_id.' AND bi_sourceId = '.(int)$source_id.'';
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
if (!$res)
return array();
return $res[0];
}
}