import apilo
This commit is contained in:
@@ -50,37 +50,122 @@ function show()
|
||||
echo $smarty->display(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.tpl');
|
||||
}
|
||||
|
||||
function getInvoices($source, $date, $type)
|
||||
{
|
||||
function getInvoices($source, $date, $type) {
|
||||
$db = $GLOBALS['db'];
|
||||
$date .= '%';
|
||||
$query = "SELECT i.*, wz.document_no AS wz_document_no, wz.id AS wz_id FROM ecommerce_invoices AS i
|
||||
LEFT JOIN ecmstockdocouts AS wz on wz.id = i.ecmstockdocout_id
|
||||
";
|
||||
$query .= " WHERE i.register_date LIKE '$date'";
|
||||
|
||||
$query = "SELECT
|
||||
i.id,
|
||||
i.document_no,
|
||||
i.type,
|
||||
i.register_date,
|
||||
i.sell_date,
|
||||
i.origin,
|
||||
i.order_no,
|
||||
i.parent_name,
|
||||
i.parent_nip,
|
||||
i.parent_address_city,
|
||||
i.parent_address_postalcode,
|
||||
i.parent_address_street,
|
||||
i.parent_address_country,
|
||||
i.parent_address_country_code,
|
||||
i.currency,
|
||||
i.total_netto,
|
||||
i.total_brutto,
|
||||
i.total_vat,
|
||||
i.url,
|
||||
i.corrected_invoice_id,
|
||||
i.ecmstockdocout_id,
|
||||
i.ecmstockdoccorrect_id,
|
||||
i.ecmsale_id,
|
||||
i.series_id,
|
||||
wz.document_no AS wz_document_no,
|
||||
wz.id AS wz_id,
|
||||
p.id as product_id,
|
||||
p.code as product_code,
|
||||
p.name as product_name,
|
||||
ip.quantity,
|
||||
ip.price_netto,
|
||||
ip.price_brutto,
|
||||
ip.price_vat,
|
||||
ip.vat_value,
|
||||
ip.code as ecommerce_code
|
||||
FROM ecommerce_invoices AS i
|
||||
LEFT JOIN ecmstockdocouts AS wz ON wz.id = i.ecmstockdocout_id
|
||||
LEFT JOIN ecommerce_invoices_products AS ip ON i.id = ip.invoice_id
|
||||
LEFT JOIN ecmproducts AS p ON ip.ecmproduct_id = p.id
|
||||
WHERE i.register_date LIKE '$date'";
|
||||
|
||||
if ($source != '') {
|
||||
if ($source == 'baselinker') {
|
||||
$query .= " AND i.origin IN ('allegro', 'shop')";
|
||||
} else if ($source == 'apilo') {
|
||||
$query .= " AND i.origin LIKE 'apilo%'";
|
||||
} else {
|
||||
$query .= " AND i.origin = '$source'";
|
||||
$query .= " AND i.origin = '" . $db->quote($source) . "'";
|
||||
}
|
||||
}
|
||||
|
||||
if ($type != '') {
|
||||
$query .= " AND i.type='$type'";
|
||||
$query .= " AND i.type = '" . $db->quote($type) . "'";
|
||||
}
|
||||
|
||||
$query .= " ORDER BY i.register_date";
|
||||
|
||||
$result = $db->query($query);
|
||||
$invoices = array();
|
||||
|
||||
while ($row = $db->fetchByAssoc($result)) {
|
||||
// format date in row register_date from mysql format into d.m.Y
|
||||
$row['register_date'] = date('d.m.Y', strtotime($row['register_date']));
|
||||
$row['sell_date'] = date('d.m.Y', strtotime($row['sell_date']));
|
||||
$row['products'] = getInvoicProducts($row['id']);
|
||||
$row['sum_by_products'] = getInvoiceSumByProducts($row['id']);
|
||||
$invoices[] = $row;
|
||||
if (!isset($invoices[$row['id']])) {
|
||||
$invoices[$row['id']] = array(
|
||||
'id' => $row['id'],
|
||||
'document_no' => $row['document_no'],
|
||||
'type' => $row['type'],
|
||||
'register_date' => date('d.m.Y', strtotime($row['register_date'])),
|
||||
'sell_date' => date('d.m.Y', strtotime($row['sell_date'])),
|
||||
'origin' => $row['origin'],
|
||||
'order_no' => $row['order_no'],
|
||||
'parent_name' => $row['parent_name'],
|
||||
'parent_nip' => $row['parent_nip'],
|
||||
'parent_address_city' => $row['parent_address_city'],
|
||||
'parent_address_postalcode' => $row['parent_address_postalcode'],
|
||||
'parent_address_street' => $row['parent_address_street'],
|
||||
'parent_address_country' => $row['parent_address_country'],
|
||||
'parent_address_country_code' => $row['parent_address_country_code'],
|
||||
'currency' => $row['currency'],
|
||||
'total_netto' => $row['total_netto'],
|
||||
'total_brutto' => $row['total_brutto'],
|
||||
'total_vat' => $row['total_vat'],
|
||||
'url' => $row['url'],
|
||||
'corrected_invoice_id' => $row['corrected_invoice_id'],
|
||||
'ecmstockdocout_id' => $row['ecmstockdocout_id'],
|
||||
'ecmstockdoccorrect_id' => $row['ecmstockdoccorrect_id'],
|
||||
'ecmsale_id' => $row['ecmsale_id'],
|
||||
'series_id' => $row['series_id'],
|
||||
'wz_document_no' => $row['wz_document_no'],
|
||||
'wz_id' => $row['wz_id'],
|
||||
'products' => array(),
|
||||
'sum_by_products' => 0
|
||||
);
|
||||
}
|
||||
|
||||
if ($row['product_id']) {
|
||||
$invoices[$row['id']]['products'][] = array(
|
||||
'id' => $row['product_id'],
|
||||
'code' => $row['product_code'],
|
||||
'name' => $row['product_name'],
|
||||
'price_netto' => $row['price_netto'],
|
||||
'price_brutto' => $row['price_brutto'],
|
||||
'quantity' => $row['quantity'],
|
||||
'ecommerce_code' => $row['ecommerce_code'],
|
||||
'vat_value' => str_replace(".00", "", $row['vat_value'])
|
||||
);
|
||||
|
||||
$invoices[$row['id']]['sum_by_products'] += ($row['price_netto'] * $row['quantity']);
|
||||
}
|
||||
}
|
||||
return $invoices;
|
||||
|
||||
return array_values($invoices);
|
||||
}
|
||||
function getInvoiceSumByProducts($invoiceId) {
|
||||
$db = $GLOBALS['db'];
|
||||
@@ -118,6 +203,7 @@ function getSources() {
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
$sources[]= $row['origin'];
|
||||
}
|
||||
$sources[] = 'apilo';
|
||||
$sources[] = 'baselinker';
|
||||
return $sources;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user