NEW: Add a sub table to manage accountancy on product/company
This commit is contained in:
parent
18d247026d
commit
00e21caa42
@ -188,7 +188,7 @@ if ($action == 'update') {
|
||||
} else {
|
||||
$db->begin();
|
||||
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_accountancy (fk_product, entity, " . $accountancy_field_name . ")";
|
||||
$sql .= " VALUES (" . ((int) $productid) . ", " . ((int) $conf->entity) . ", " . $accounting->account_number . ")";
|
||||
$sql .= " ON DUPLICATE KEY UPDATE " . $accountancy_field_name . " = " . $accounting->account_number;
|
||||
@ -269,7 +269,7 @@ if (empty($pcgvercode)) {
|
||||
}
|
||||
|
||||
$sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell, pa.accountancy_code_sell_intra, pa.accountancy_code_sell_export,";
|
||||
$sql .= " pa.accountancy_code_buy, pa.accountancy_code_buy_intra, pa.accountancy_code_buy_export,";
|
||||
} else {
|
||||
@ -279,7 +279,7 @@ if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
$sql .= " p.tms, p.fk_product_type as product_type,";
|
||||
$sql .= " aa.rowid as aaid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = pa." . $accountancy_field_name . " AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) . "'";
|
||||
} else {
|
||||
@ -287,7 +287,7 @@ if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
}
|
||||
$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
|
||||
if (strlen(trim($search_current_account))) {
|
||||
$sql .= natural_search((!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa." : "p.") . $accountancy_field_name, $search_current_account);
|
||||
$sql .= natural_search((!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa." : "p.") . $accountancy_field_name, $search_current_account);
|
||||
}
|
||||
if ($search_current_account_valid == 'withoutvalidaccount') {
|
||||
$sql .= " AND aa.account_number IS NULL";
|
||||
@ -466,7 +466,7 @@ if ($result) {
|
||||
} else {
|
||||
print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
|
||||
}
|
||||
print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], (empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa." : "p.") . $accountancy_field_name, "", $param, '', $sortfield, $sortorder);
|
||||
print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa." : "p.") . $accountancy_field_name, "", $param, '', $sortfield, $sortorder);
|
||||
print_liste_field_titre("AssignDedicatedAccountingAccount");
|
||||
$clickpitco = $form->showCheckAddButtons('checkforselect', 1);
|
||||
print_liste_field_titre($clickpitco, '', '', '', '', '', '', '', 'center ');
|
||||
|
||||
@ -94,7 +94,7 @@ $formaccounting = new FormAccounting($db);
|
||||
if (!empty($id)) {
|
||||
$sql = "SELECT f.ref, f.rowid as facid, l.fk_product, l.description, l.price,";
|
||||
$sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell as code_sell,";
|
||||
} else {
|
||||
$sql .= " p.accountancy_code_sell as code_sell,";
|
||||
@ -102,7 +102,7 @@ if (!empty($id)) {
|
||||
$sql .= " l.fk_code_ventilation, aa.account_number, aa.label";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON l.fk_code_ventilation = aa.rowid";
|
||||
|
||||
@ -125,7 +125,7 @@ if ($action == 'validatehistory') {
|
||||
$sql = "SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype,";
|
||||
$sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
|
||||
$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell as code_sell, pa.accountancy_code_sell_intra as code_sell_intra, pa.accountancy_code_sell_export as code_sell_export,";
|
||||
} else {
|
||||
$sql .= " p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
|
||||
@ -148,7 +148,7 @@ if ($action == 'validatehistory') {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$alias_company_accounting = !empty($conf->global->ACCOUNTANCY_COMPANY_SHARED) ? "sa" : "s";
|
||||
$alias_product_accounting = !empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa" : "p";
|
||||
$alias_product_accounting = !empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa" : "p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON " . $alias_product_accounting . ".accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_accounting . ".accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_accounting . ".accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
|
||||
|
||||
@ -179,7 +179,7 @@ $sql = "SELECT f.rowid as facid, f.ref as ref, f.type, f.datef, f.ref_client,";
|
||||
$sql .= " fd.rowid, fd.description, fd.product_type as line_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc,";
|
||||
$sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.code_client,";
|
||||
$sql .= " p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label,";
|
||||
if (empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell,";
|
||||
} else {
|
||||
$sql .= " p.accountancy_code_sell,";
|
||||
@ -193,7 +193,7 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
|
||||
|
||||
@ -215,7 +215,7 @@ if (empty($chartaccountcode)) {
|
||||
$sql = "SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype,";
|
||||
$sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
|
||||
$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
|
||||
if (empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell as code_sell, pa.accountancy_code_sell_intra as code_sell_intra, pa.accountancy_code_sell_export as code_sell_export,";
|
||||
$sql .= " pa.accountancy_code_buy as code_buy, pa.accountancy_code_buy_intra as code_buy_intra, pa.accountancy_code_buy_export as code_buy_export,";
|
||||
} else {
|
||||
@ -226,7 +226,7 @@ $sql .= " p.tosell as status, p.tobuy as status_buy,";
|
||||
$sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
|
||||
$sql .= " co.code as country_code, co.label as country_label,";
|
||||
$sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " sa.accountancy_code_sell as company_code_sell";
|
||||
} else {
|
||||
$sql .= " s.accountancy_code_sell as company_code_sell";
|
||||
@ -242,11 +242,11 @@ if (!empty($conf->global->ACCOUNTANCY_COMPANY_SHARED)) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as l ON f.rowid = l.fk_facture";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$alias_company_accounting = empty($conf->global->MAIN_COMPANY_ACCOUNTANCY_NOT_SHARED) ? "s" : "sa";
|
||||
$alias_product_accounting = empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_NOT_SHARED) ? "p" : "pa";
|
||||
$alias_company_accounting = empty($conf->global->MAIN_COMPANY_ACCOUNTANCY_SHARED) ? "s" : "sa";
|
||||
$alias_product_accounting = empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "p" : "pa";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON " . $alias_product_accounting . ".accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_accounting . ".accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_accounting . ".accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
|
||||
|
||||
@ -102,13 +102,13 @@ $sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.ref_client, f.date_lim_r
|
||||
$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code,";
|
||||
$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,";
|
||||
$sql .= " p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell";
|
||||
} else {
|
||||
$sql .= " p.accountancy_code_sell";
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
|
||||
|
||||
@ -220,7 +220,7 @@ if (empty($chartaccountcode)) {
|
||||
$sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype,";
|
||||
$sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
|
||||
$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell as code_sell, pa.accountancy_code_sell_intra as code_sell_intra, pa.accountancy_code_sell_export as code_sell_export,";
|
||||
$sql .= " pa.accountancy_code_buy as code_buy, pa.accountancy_code_buy_intra as code_buy_intra, pa.accountancy_code_buy_export as code_buy_export,";
|
||||
} else {
|
||||
@ -231,7 +231,7 @@ $sql .= " p.tosell as status, p.tobuy as status_buy,";
|
||||
$sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
|
||||
$sql .= " co.code as country_code, co.label as country_label,";
|
||||
$sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_COMPANY_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_COMPANY_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " sa.accountancy_code_buy as company_code_buy";
|
||||
} else {
|
||||
$sql .= " s.accountancy_code_buy as company_code_buy";
|
||||
@ -241,16 +241,16 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
|
||||
if (!empty($conf->global->ACCOUNTANCY_COMPANY_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_COMPANY_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_accounting as sa ON sa.fk_soc = s.rowid AND sa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$alias_company_accounting = !empty($conf->global->ACCOUNTANCY_COMPANY_SHARED) ? "sa" : "s";
|
||||
$alias_product_accounting = !empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa" : "p";
|
||||
$alias_company_accounting = !empty($conf->global->MAIN_COMPANY_ACCOUNTANCY_SHARED) ? "sa" : "s";
|
||||
$alias_product_accounting = !empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa" : "p";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON " . $alias_product_accounting . ".accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_accounting . ".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_accounting . ".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
|
||||
|
||||
@ -112,7 +112,7 @@ $sql = "SELECT f.rowid, f.ref, f.type, f.datef, f.ref_client,";
|
||||
$sql .= " fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc, fd.localtax1_tx, fd.localtax2_tx, fd.total_localtax1, fd.total_localtax2, fd.rowid as id, fd.situation_percent,";
|
||||
$sql .= " s.rowid as socid, s.nom as name, s.code_compta, s.client,";
|
||||
$sql .= " p.rowid as pid, p.ref as pref,";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " pa.accountancy_code_sell,";
|
||||
} else {
|
||||
$sql .= " p.accountancy_code_sell,";
|
||||
@ -120,7 +120,7 @@ if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
$sql .= " ct.accountancy_code_sell as account_tva, ct.recuperableonly";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$sql .= " JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
|
||||
|
||||
@ -207,7 +207,7 @@ class modFacture extends DolibarrModules
|
||||
//--------
|
||||
$r = 1;
|
||||
|
||||
$alias_product_accounting = empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa" : "p";
|
||||
$alias_product_accounting = empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa" : "p";
|
||||
$this->export_code[$r] = $this->rights_class.'_'.$r;
|
||||
$this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
|
||||
$this->export_icon[$r] = 'invoice';
|
||||
@ -295,7 +295,7 @@ class modFacture extends DolibarrModules
|
||||
$this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
|
||||
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
|
||||
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
|
||||
|
||||
@ -176,7 +176,7 @@ class modProduct extends DolibarrModules
|
||||
//--------
|
||||
$r = 0;
|
||||
|
||||
$alias_product_accounting = empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa" : "p";
|
||||
$alias_product_accounting = empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa" : "p";
|
||||
$r++;
|
||||
$this->export_code[$r] = $this->rights_class.'_'.$r;
|
||||
$this->export_label[$r] = "Products"; // Translation key (used only if key ExportDataset_xxx_z not found)
|
||||
@ -294,7 +294,7 @@ class modProduct extends DolibarrModules
|
||||
}
|
||||
$this->export_sql_start[$r] = 'SELECT DISTINCT ';
|
||||
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
|
||||
@ -445,7 +445,7 @@ class modProduct extends DolibarrModules
|
||||
$this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p2.rowid'=>"subproduct", 'p2.ref'=>"subproduct", 'p2.label'=>"subproduct", 'p2.description'=>"subproduct"));
|
||||
$this->export_sql_start[$r] = 'SELECT DISTINCT ';
|
||||
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
|
||||
|
||||
@ -143,7 +143,7 @@ class modService extends DolibarrModules
|
||||
//--------
|
||||
$r = 0;
|
||||
|
||||
$alias_product_accounting = empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED) ? "pa" : "p";
|
||||
$alias_product_accounting = empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "pa" : "p";
|
||||
$r++;
|
||||
$this->export_code[$r] = $this->rights_class.'_'.$r;
|
||||
$this->export_label[$r] = "Services"; // Translation key (used only if key ExportDataset_xxx_z not found)
|
||||
@ -257,7 +257,7 @@ class modService extends DolibarrModules
|
||||
}
|
||||
$this->export_sql_start[$r] = 'SELECT DISTINCT ';
|
||||
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
|
||||
if (!empty($conf->global->ACCOUNTANCY_PRODUCT_SHARED)) {
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
|
||||
|
||||
@ -273,3 +273,33 @@ DELETE FROM llx_boxes_def WHERE file IN ('box_ticket_by_severity.php', 'box_nb_t
|
||||
-- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_graph_nb_ticket_last_x_days.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_graph_nb_ticket_last_x_days.php' AND entity = 1);
|
||||
-- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_graph_nb_tickets_type.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_graph_nb_tickets_type.php' AND entity = 1);
|
||||
-- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_graph_new_vs_close_ticket.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_graph_new_vs_close_ticket.php' AND entity = 1);
|
||||
|
||||
create table llx_product_accountancy
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_product integer,
|
||||
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
||||
accountancy_code_sell varchar(32), -- Selling accountancy code
|
||||
accountancy_code_sell_intra varchar(32), -- Selling accountancy code for vat intracommunity
|
||||
accountancy_code_sell_export varchar(32), -- Selling accountancy code for vat export
|
||||
accountancy_code_buy varchar(32), -- Buying accountancy code
|
||||
accountancy_code_buy_intra varchar(32), -- Buying accountancy code for vat intracommunity
|
||||
accountancy_code_buy_export varchar(32) -- Buying accountancy code for vat import
|
||||
)ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_product_accountancy ADD INDEX idx_product_accountancy_fk_product (fk_product);
|
||||
ALTER TABLE llx_product_accountancy ADD UNIQUE INDEX uk_product_accountancy (fk_product, entity);
|
||||
|
||||
create table llx_societe_accountancy
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_soc integer,
|
||||
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
||||
-- code_compta varchar(24), -- code compta client
|
||||
-- code_compta_fournisseur varchar(24), -- code compta founisseur
|
||||
accountancy_code_sell varchar(32), -- Selling accountancy code
|
||||
accountancy_code_buy varchar(32) -- Buying accountancy code
|
||||
)ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_societe_accountancy ADD INDEX idx_societe_accountancy_fk_soc (fk_soc);
|
||||
ALTER TABLE llx_societe_accountancy ADD UNIQUE INDEX uk_societe_accountancy (fk_soc, entity);
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
|
||||
* Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
|
||||
* Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
|
||||
* Copyright (C) 2011-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
||||
* Copyright (C) 2011-2021 Open-DSI <support@open-dsi.fr>
|
||||
* Copyright (C) 2014 Henry Florian <florian.henry@open-concept.pro>
|
||||
* Copyright (C) 2014-2016 Philippe Grand <philippe.grand@atoo-net.com>
|
||||
* Copyright (C) 2014 Ion agorria <ion@agorria.com>
|
||||
@ -660,12 +660,14 @@ class Product extends CommonObject
|
||||
$sql .= ", price_base_type";
|
||||
$sql .= ", tobuy";
|
||||
$sql .= ", tosell";
|
||||
$sql .= ", accountancy_code_buy";
|
||||
$sql .= ", accountancy_code_buy_intra";
|
||||
$sql .= ", accountancy_code_buy_export";
|
||||
$sql .= ", accountancy_code_sell";
|
||||
$sql .= ", accountancy_code_sell_intra";
|
||||
$sql .= ", accountancy_code_sell_export";
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= ", accountancy_code_buy";
|
||||
$sql .= ", accountancy_code_buy_intra";
|
||||
$sql .= ", accountancy_code_buy_export";
|
||||
$sql .= ", accountancy_code_sell";
|
||||
$sql .= ", accountancy_code_sell_intra";
|
||||
$sql .= ", accountancy_code_sell_export";
|
||||
}
|
||||
$sql .= ", canvas";
|
||||
$sql .= ", finished";
|
||||
$sql .= ", tobatch";
|
||||
@ -685,12 +687,14 @@ class Product extends CommonObject
|
||||
$sql .= ", '".$this->db->escape($this->price_base_type)."'";
|
||||
$sql .= ", ".$this->status;
|
||||
$sql .= ", ".$this->status_buy;
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_buy_intra)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_buy_export)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_sell)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_sell_intra)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_sell_export)."'";
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_buy)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_buy_intra)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_buy_export)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_sell)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_sell_intra)."'";
|
||||
$sql .= ", '".$this->db->escape($this->accountancy_code_sell_export)."'";
|
||||
}
|
||||
$sql .= ", '".$this->db->escape($this->canvas)."'";
|
||||
$sql .= ", ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : (int) $this->finished);
|
||||
$sql .= ", ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : $this->status_batch);
|
||||
@ -718,6 +722,35 @@ class Product extends CommonObject
|
||||
$error++;
|
||||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
|
||||
// update accountancy for this entity
|
||||
if (!$error && !empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_accounting (";
|
||||
$sql .= " fk_product";
|
||||
$sql .= ", entity";
|
||||
$sql .= ", accountancy_code_buy";
|
||||
$sql .= ", accountancy_code_buy_intra";
|
||||
$sql .= ", accountancy_code_buy_export";
|
||||
$sql .= ", accountancy_code_sell";
|
||||
$sql .= ", accountancy_code_sell_intra";
|
||||
$sql .= ", accountancy_code_sell_export";
|
||||
$sql .= ") VALUES (";
|
||||
$sql .= $this->id;
|
||||
$sql .= ", " . $conf->entity;
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_buy) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_buy_intra) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_buy_export) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_sell) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_sell_intra) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_sell_export) . "'";
|
||||
$sql .= ")";
|
||||
$result = $this->db->query($sql);
|
||||
if (!$result) {
|
||||
$error++;
|
||||
$this->error = 'ErrorFailedToInsertAccountancyForEntity';
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$error++;
|
||||
$this->error = 'ErrorFailedToGetInsertedId';
|
||||
@ -1051,12 +1084,14 @@ class Product extends CommonObject
|
||||
$sql .= ", fk_state = ".($this->state_id > 0 ? (int) $this->state_id : 'null');
|
||||
$sql .= ", note = ".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : 'null');
|
||||
$sql .= ", duration = '".$this->db->escape($this->duration_value.$this->duration_unit)."'";
|
||||
$sql .= ", accountancy_code_buy = '".$this->db->escape($this->accountancy_code_buy)."'";
|
||||
$sql .= ", accountancy_code_buy_intra = '".$this->db->escape($this->accountancy_code_buy_intra)."'";
|
||||
$sql .= ", accountancy_code_buy_export = '".$this->db->escape($this->accountancy_code_buy_export)."'";
|
||||
$sql .= ", accountancy_code_sell= '".$this->db->escape($this->accountancy_code_sell)."'";
|
||||
$sql .= ", accountancy_code_sell_intra= '".$this->db->escape($this->accountancy_code_sell_intra)."'";
|
||||
$sql .= ", accountancy_code_sell_export= '".$this->db->escape($this->accountancy_code_sell_export)."'";
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) . "'";
|
||||
$sql .= ", accountancy_code_buy_intra = '" . $this->db->escape($this->accountancy_code_buy_intra) . "'";
|
||||
$sql .= ", accountancy_code_buy_export = '" . $this->db->escape($this->accountancy_code_buy_export) . "'";
|
||||
$sql .= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) . "'";
|
||||
$sql .= ", accountancy_code_sell_intra= '" . $this->db->escape($this->accountancy_code_sell_intra) . "'";
|
||||
$sql .= ", accountancy_code_sell_export= '" . $this->db->escape($this->accountancy_code_sell_export) . "'";
|
||||
}
|
||||
$sql .= ", desiredstock = ".((isset($this->desiredstock) && is_numeric($this->desiredstock)) ? (float) $this->desiredstock : "null");
|
||||
$sql .= ", cost_price = ".($this->cost_price != '' ? $this->db->escape($this->cost_price) : 'null');
|
||||
$sql .= ", fk_unit= ".(!$this->fk_unit ? 'NULL' : (int) $this->fk_unit);
|
||||
@ -1083,6 +1118,36 @@ class Product extends CommonObject
|
||||
|
||||
$action = 'update';
|
||||
|
||||
// update accountancy for this entity
|
||||
if (!$error && !empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_accounting WHERE fk_product = " . $this->id . " AND entity = " . $conf->entity);
|
||||
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_accounting (";
|
||||
$sql .= " fk_product";
|
||||
$sql .= ", entity";
|
||||
$sql .= ", accountancy_code_buy";
|
||||
$sql .= ", accountancy_code_buy_intra";
|
||||
$sql .= ", accountancy_code_buy_export";
|
||||
$sql .= ", accountancy_code_sell";
|
||||
$sql .= ", accountancy_code_sell_intra";
|
||||
$sql .= ", accountancy_code_sell_export";
|
||||
$sql .= ") VALUES (";
|
||||
$sql .= $this->id;
|
||||
$sql .= ", " . $conf->entity;
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_buy) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_buy_intra) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_buy_export) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_sell) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_sell_intra) . "'";
|
||||
$sql .= ", '" . $this->db->escape($this->accountancy_code_sell_export) . "'";
|
||||
$sql .= ")";
|
||||
$result = $this->db->query($sql);
|
||||
if (!$result) {
|
||||
$error++;
|
||||
$this->error = 'ErrorFailedToUpdateAccountancyForEntity';
|
||||
}
|
||||
}
|
||||
|
||||
// Actions on extra fields
|
||||
if (!$error) {
|
||||
$result = $this->insertExtraFields();
|
||||
@ -2096,16 +2161,22 @@ class Product extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
|
||||
$sql = "SELECT rowid, ref, ref_ext, label, description, url, note_public, note as note_private, customcode, fk_country, fk_state, price, price_ttc,";
|
||||
$sql .= " price_min, price_min_ttc, price_base_type, cost_price, default_vat_code, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, tosell,";
|
||||
$sql .= " tobuy, fk_product_type, duration, fk_default_warehouse, seuil_stock_alerte, canvas, net_measure, net_measure_units, weight, weight_units,";
|
||||
$sql .= " length, length_units, width, width_units, height, height_units,";
|
||||
$sql .= " surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,";
|
||||
$sql .= " accountancy_code_buy, accountancy_code_buy_intra, accountancy_code_buy_export,";
|
||||
$sql .= " accountancy_code_sell, accountancy_code_sell_intra, accountancy_code_sell_export, stock, pmp,";
|
||||
$sql .= " datec, tms, import_key, entity, desiredstock, tobatch, fk_unit,";
|
||||
$sql .= " fk_price_expression, price_autogen, model_pdf";
|
||||
$sql = "SELECT p.rowid, p.ref, p.ref_ext, p.label, p.description, p.url, p.note_public, p.note as note_private, p.customcode, p.fk_country, p.fk_state, p.price, p.price_ttc,";
|
||||
$sql .= " p.price_min, p.price_min_ttc, p.price_base_type, p.cost_price, p.default_vat_code, p.tva_tx, p.recuperableonly as tva_npr, p.localtax1_tx, p.localtax2_tx, p.localtax1_type, p.localtax2_type, p.tosell,";
|
||||
$sql .= " p.tobuy, p.fk_product_type, p.duration, p.fk_default_warehouse, p.seuil_stock_alerte, p.canvas, p.net_measure, p.net_measure_units, p.weight, p.weight_units,";
|
||||
$sql .= " p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,";
|
||||
$sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,";
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
|
||||
} else {
|
||||
$sql .= " pa.accountancy_code_buy, pa.accountancy_code_buy_intra, pa.accountancy_code_buy_export, pa.accountancy_code_sell, pa.accountancy_code_sell_intra, pa.accountancy_code_sell_export,";
|
||||
}
|
||||
$sql .= " p.stock,p.pmp, p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.fk_unit,";
|
||||
$sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product";
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
if ($id) {
|
||||
$sql .= " WHERE rowid = ".(int) $id;
|
||||
} else {
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
* Copyright (C) 2013 Adolfo segura <adolfo.segura@gmail.com>
|
||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
|
||||
* Copyright (C) 2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
||||
* Copyright (C) 2020-2021 Open-DSI <support@open-dsi.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -199,6 +199,8 @@ if (empty($conf->global->PRODUIT_MULTIPRICES)) {
|
||||
|
||||
$isInEEC = isInEEC($mysoc);
|
||||
|
||||
$alias_product_accounting = empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED) ? "p" : "pa";
|
||||
|
||||
// Definition of fields for lists
|
||||
$arrayfields = array(
|
||||
'p.ref'=>array('label'=>"Ref", 'checked'=>1),
|
||||
@ -234,12 +236,12 @@ $arrayfields = array(
|
||||
'p.tobatch'=>array('label'=>"ManageLotSerial", 'checked'=>0, 'enabled'=>(!empty($conf->productbatch->enabled)), 'position'=>60),
|
||||
'p.fk_country'=>array('label'=>"Country", 'checked'=>0, 'position'=>100),
|
||||
'p.fk_state'=>array('label'=>"State", 'checked'=>0, 'position'=>101),
|
||||
'p.accountancy_code_sell'=>array('label'=>"ProductAccountancySellCode", 'checked'=>0, 'position'=>400),
|
||||
'p.accountancy_code_sell_intra'=>array('label'=>"ProductAccountancySellIntraCode", 'checked'=>0, 'enabled'=>$isInEEC, 'position'=>401),
|
||||
'p.accountancy_code_sell_export'=>array('label'=>"ProductAccountancySellExportCode", 'checked'=>0, 'position'=>402),
|
||||
'p.accountancy_code_buy'=>array('label'=>"ProductAccountancyBuyCode", 'checked'=>0, 'position'=>403),
|
||||
'p.accountancy_code_buy_intra'=>array('label'=>"ProductAccountancyBuyIntraCode", 'checked'=>0, 'enabled'=>$isInEEC, 'position'=>404),
|
||||
'p.accountancy_code_buy_export'=>array('label'=>"ProductAccountancyBuyExportCode", 'checked'=>0, 'position'=>405),
|
||||
$alias_product_accounting . '.accountancy_code_sell'=>array('label'=>"ProductAccountancySellCode", 'checked'=>0, 'position'=>400),
|
||||
$alias_product_accounting . '.accountancy_code_sell_intra'=>array('label'=>"ProductAccountancySellIntraCode", 'checked'=>0, 'enabled'=>$isInEEC, 'position'=>401),
|
||||
$alias_product_accounting . '.accountancy_code_sell_export'=>array('label'=>"ProductAccountancySellExportCode", 'checked'=>0, 'position'=>402),
|
||||
$alias_product_accounting . '.accountancy_code_buy'=>array('label'=>"ProductAccountancyBuyCode", 'checked'=>0, 'position'=>403),
|
||||
$alias_product_accounting . '.accountancy_code_buy_intra'=>array('label'=>"ProductAccountancyBuyIntraCode", 'checked'=>0, 'enabled'=>$isInEEC, 'position'=>404),
|
||||
$alias_product_accounting . '.accountancy_code_buy_export'=>array('label'=>"ProductAccountancyBuyExportCode", 'checked'=>0, 'position'=>405),
|
||||
'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
|
||||
'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
|
||||
'p.tosell'=>array('label'=>$langs->transnoentitiesnoconv("Status").' ('.$langs->transnoentitiesnoconv("Sell").')', 'checked'=>1, 'position'=>1000),
|
||||
@ -357,8 +359,12 @@ if ($search_type != '' && $search_type != '-1') {
|
||||
|
||||
$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type, p.entity,';
|
||||
$sql .= ' p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
|
||||
$sql .= ' p.tobatch, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,';
|
||||
$sql .= ' p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,';
|
||||
$sql .= ' p.tobatch,';
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
|
||||
} else {
|
||||
$sql .= " pa.accountancy_code_sell, pa.accountancy_code_sell_intra, pa.accountancy_code_sell_export, pa.accountancy_code_buy, pa.accountancy_code_buy_intra, pa.accountancy_code_buy_export,";
|
||||
}
|
||||
$sql .= ' p.datec as date_creation, p.tms as date_update, p.pmp, p.stock, p.cost_price,';
|
||||
$sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, fk_country, fk_state,';
|
||||
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
|
||||
@ -379,6 +385,9 @@ $parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
|
||||
if (!empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_accounting as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int)$conf->entity);
|
||||
}
|
||||
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)";
|
||||
}
|
||||
@ -483,22 +492,22 @@ if ($search_finished >= 0 && $search_finished !== '') {
|
||||
$sql .= " AND p.finished = ".$search_finished;
|
||||
}
|
||||
if ($search_accountancy_code_sell) {
|
||||
$sql .= natural_search('p.accountancy_code_sell', $search_accountancy_code_sell);
|
||||
$sql .= natural_search($alias_product_accounting . '.accountancy_code_sell', $search_accountancy_code_sell);
|
||||
}
|
||||
if ($search_accountancy_code_sell_intra) {
|
||||
$sql .= natural_search('p.accountancy_code_sell_intra', $search_accountancy_code_sell_intra);
|
||||
$sql .= natural_search($alias_product_accounting . '.accountancy_code_sell_intra', $search_accountancy_code_sell_intra);
|
||||
}
|
||||
if ($search_accountancy_code_sell_export) {
|
||||
$sql .= natural_search('p.accountancy_code_sell_export', $search_accountancy_code_sell_export);
|
||||
$sql .= natural_search($alias_product_accounting . '.accountancy_code_sell_export', $search_accountancy_code_sell_export);
|
||||
}
|
||||
if ($search_accountancy_code_buy) {
|
||||
$sql .= natural_search('p.accountancy_code_buy', $search_accountancy_code_buy);
|
||||
$sql .= natural_search($alias_product_accounting . '.accountancy_code_buy', $search_accountancy_code_buy);
|
||||
}
|
||||
if ($search_accountancy_code_buy_intra) {
|
||||
$sql .= natural_search('p.accountancy_code_buy_intra', $search_accountancy_code_buy_intra);
|
||||
$sql .= natural_search($alias_product_accounting . '.accountancy_code_buy_intra', $search_accountancy_code_buy_intra);
|
||||
}
|
||||
if ($search_accountancy_code_buy_export) {
|
||||
$sql .= natural_search('p.accountancy_code_buy_export', $search_accountancy_code_buy_export);
|
||||
$sql .= natural_search($alias_product_accounting . '.accountancy_code_buy_export', $search_accountancy_code_buy_export);
|
||||
}
|
||||
|
||||
// Add where from extra fields
|
||||
@ -509,8 +518,12 @@ $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // No
|
||||
$sql .= $hookmanager->resPrint;
|
||||
$sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type,";
|
||||
$sql .= " p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,";
|
||||
$sql .= ' p.datec, p.tms, p.entity, p.tobatch, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,';
|
||||
$sql .= ' p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.pmp, p.cost_price, p.stock,';
|
||||
$sql .= ' p.datec, p.tms, p.entity, p.tobatch, p.pmp, p.cost_price, p.stock,';
|
||||
if (empty($conf->global->MAIN_PRODUCT_ACCOUNTANCY_SHARED)) {
|
||||
$sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
|
||||
} else {
|
||||
$sql .= " pa.accountancy_code_sell, pa.accountancy_code_sell_intra, pa.accountancy_code_sell_export, pa.accountancy_code_buy, pa.accountancy_code_buy_intra, pa.accountancy_code_buy_export,";
|
||||
}
|
||||
$sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.fk_country, p.fk_state';
|
||||
if (!empty($conf->global->PRODUCT_USE_UNITS)) {
|
||||
$sql .= ', p.fk_unit, cu.label';
|
||||
@ -989,23 +1002,23 @@ if ($resql) {
|
||||
print '<td class="liste_titre center">'.$formcompany->select_state($search_state, $search_country).'</td>';
|
||||
}
|
||||
// Accountancy code sell
|
||||
if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell']['checked'])) {
|
||||
print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell" value="'.dol_escape_htmltag($search_accountancy_code_sell).'"></td>';
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell_intra']['checked'])) {
|
||||
print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell_intra" value="'.dol_escape_htmltag($search_accountancy_code_sell_intra).'"></td>';
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell_export']['checked'])) {
|
||||
print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell_export" value="'.dol_escape_htmltag($search_accountancy_code_sell_export).'"></td>';
|
||||
}
|
||||
// Accountancy code buy
|
||||
if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy']['checked'])) {
|
||||
print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy" value="'.dol_escape_htmltag($search_accountancy_code_buy).'"></td>';
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy_intra']['checked'])) {
|
||||
print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy_intra" value="'.dol_escape_htmltag($search_accountancy_code_buy_intra).'"></td>';
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy_export']['checked'])) {
|
||||
print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy_export" value="'.dol_escape_htmltag($search_accountancy_code_buy_export).'"></td>';
|
||||
}
|
||||
// Extra fields
|
||||
@ -1152,23 +1165,23 @@ if ($resql) {
|
||||
if (!empty($arrayfields['p.fk_state']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.fk_state']['label'], $_SERVER["PHP_SELF"], "p.fk_state", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"], "p.accountancy_code_sell", "", $param, '', $sortfield, $sortorder);
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell']['checked'])) {
|
||||
print_liste_field_titre($arrayfields[$alias_product_accounting . '.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"], $alias_product_accounting . ".accountancy_code_sell", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.accountancy_code_sell_intra']['label'], $_SERVER["PHP_SELF"], "p.accountancy_code_sell_intra", "", $param, '', $sortfield, $sortorder);
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell_intra']['checked'])) {
|
||||
print_liste_field_titre($arrayfields[$alias_product_accounting . '.accountancy_code_sell_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_accounting . ".accountancy_code_sell_intra", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.accountancy_code_sell_export']['label'], $_SERVER["PHP_SELF"], "p.accountancy_code_sell_export", "", $param, '', $sortfield, $sortorder);
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell_export']['checked'])) {
|
||||
print_liste_field_titre($arrayfields[$alias_product_accounting . '.accountancy_code_sell_export']['label'], $_SERVER["PHP_SELF"], $alias_product_accounting . ".accountancy_code_sell_export", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"], "p.accountancy_code_buy", "", $param, '', $sortfield, $sortorder);
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy']['checked'])) {
|
||||
print_liste_field_titre($arrayfields[$alias_product_accounting . '.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"], $alias_product_accounting . ".accountancy_code_buy", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.accountancy_code_buy_intra']['label'], $_SERVER["PHP_SELF"], "p.accountancy_code_buy_intra", "", $param, '', $sortfield, $sortorder);
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy_intra']['checked'])) {
|
||||
print_liste_field_titre($arrayfields[$alias_product_accounting . '.accountancy_code_buy_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_accounting . ".accountancy_code_buy_intra", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) {
|
||||
print_liste_field_titre($arrayfields['p.accountancy_code_buy_export']['label'], $_SERVER["PHP_SELF"], "p.accountancy_code_buy_export", "", $param, '', $sortfield, $sortorder);
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy_export']['checked'])) {
|
||||
print_liste_field_titre($arrayfields[$alias_product_accounting . '.accountancy_code_buy_export']['label'], $_SERVER["PHP_SELF"], $alias_product_accounting . ".accountancy_code_buy_export", "", $param, '', $sortfield, $sortorder);
|
||||
}
|
||||
// Extra fields
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
|
||||
@ -1692,38 +1705,38 @@ if ($resql) {
|
||||
}
|
||||
}
|
||||
// Accountancy code sell
|
||||
if (!empty($arrayfields['p.accountancy_code_sell']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell']['checked'])) {
|
||||
print '<td>'.$obj->accountancy_code_sell.'</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell_intra']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell_intra']['checked'])) {
|
||||
print '<td>'.$obj->accountancy_code_sell_intra.'</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_sell_export']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_sell_export']['checked'])) {
|
||||
print '<td>'.$obj->accountancy_code_sell_export.'</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
}
|
||||
// Accountancy code buy
|
||||
if (!empty($arrayfields['p.accountancy_code_buy']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy']['checked'])) {
|
||||
print '<td>'.$obj->accountancy_code_buy.'</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy_intra']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy_intra']['checked'])) {
|
||||
print '<td>'.$obj->accountancy_code_buy_intra.'</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
}
|
||||
}
|
||||
if (!empty($arrayfields['p.accountancy_code_buy_export']['checked'])) {
|
||||
if (!empty($arrayfields[$alias_product_accounting . '.accountancy_code_buy_export']['checked'])) {
|
||||
print '<td>'.$obj->accountancy_code_buy_export.'</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user