diff --git a/htdocs/accountancy/admin/defaultaccounts.php b/htdocs/accountancy/admin/defaultaccounts.php
index c0c3f835481..7f3ba99a157 100644
--- a/htdocs/accountancy/admin/defaultaccounts.php
+++ b/htdocs/accountancy/admin/defaultaccounts.php
@@ -54,19 +54,27 @@ $list_account_main = array (
$list_account = array ();
$list_account[] = '---Product---';
-$list_account[] = 'ACCOUNTING_PRODUCT_BUY_ACCOUNT';
$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT';
if ($mysoc->isInEEC()) {
$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT';
}
$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT';
+$list_account[] = 'ACCOUNTING_PRODUCT_BUY_ACCOUNT';
+if ($mysoc->isInEEC()) {
+ $list_account[] = 'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT';
+}
+$list_account[] = 'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT';
$list_account[] = '---Service---';
-$list_account[] = 'ACCOUNTING_SERVICE_BUY_ACCOUNT';
$list_account[] = 'ACCOUNTING_SERVICE_SOLD_ACCOUNT';
if ($mysoc->isInEEC()) {
$list_account[] = 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT';
}
$list_account[] = 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT';
+$list_account[] = 'ACCOUNTING_SERVICE_BUY_ACCOUNT';
+if ($mysoc->isInEEC()) {
+ $list_account[] = 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT';
+}
+$list_account[] = 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT';
$list_account[] = '---Other---';
$list_account[] = 'ACCOUNTING_VAT_BUY_ACCOUNT';
$list_account[] = 'ACCOUNTING_VAT_SOLD_ACCOUNT';
diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php
index 60c9c88f0c8..0e68703846e 100644
--- a/htdocs/accountancy/admin/productaccount.php
+++ b/htdocs/accountancy/admin/productaccount.php
@@ -117,7 +117,9 @@ if ($action == 'update') {
'ACCOUNTANCY_SELL',
'ACCOUNTANCY_SELL_INTRA',
'ACCOUNTANCY_SELL_EXPORT',
- 'ACCOUNTANCY_BUY'
+ 'ACCOUNTANCY_BUY',
+ 'ACCOUNTANCY_BUY_INTRA',
+ 'ACCOUNTANCY_BUY_EXPORT'
);
if (in_array($accounting_product_mode, $accounting_product_modes)) {
@@ -159,6 +161,12 @@ if ($action == 'update') {
if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
$sql .= " SET accountancy_code_buy = ".$accounting->account_number;
}
+ if ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ $sql .= " SET accountancy_code_buy = ".$accounting->account_number;
+ }
+ if ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ $sql .= " SET accountancy_code_buy = ".$accounting->account_number;
+ }
if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
$sql .= " SET accountancy_code_sell = ".$accounting->account_number;
}
@@ -204,7 +212,11 @@ $form = new FormAccounting($db);
$accounting = new AccountingAccount($db);
// TODO: we should need to check if result is already exists accountaccount rowid.....
$aarowid_servbuy = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
+$aarowid_servbuy_intra = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT, 1);
+$aarowid_servbuy_export = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT, 1);
$aarowid_prodbuy = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
+$aarowid_prodbuy_intra = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT, 1);
+$aarowid_prodbuy_export = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT, 1);
$aarowid_servsell = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
$aarowid_servsell_intra = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT, 1);
$aarowid_servsell_export = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT, 1);
@@ -213,7 +225,11 @@ $aarowid_prodsell_intra = $accounting->fetch('', $conf->global->ACCOUNTING_P
$aarowid_prodsell_export = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT, 1);
$aacompta_servbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+$aacompta_servbuy_intra = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
+$aacompta_servbuy_export = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
$aacompta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+$aacompta_prodbuy_intra = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
+$aacompta_prodbuy_export = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
$aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
$aacompta_servsell_intra = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
$aacompta_servsell_export = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
@@ -228,7 +244,8 @@ $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'p
if (empty($pcgvercode)) $pcgvercode=$pcgverid;
$sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy,";
-$sql.= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy,";
+$sql.= " 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.tms, p.fk_product_type as product_type,";
$sql.= " aa.rowid as aaid";
$sql.= " FROM " . MAIN_DB_PREFIX . "product as p";
@@ -236,6 +253,14 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON";
if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
$sql.=" p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
}
+elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA')
+{
+ $sql.=" p.accountancy_code_buy_intra = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
+}
+elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT')
+{
+ $sql.=" p.accountancy_code_buy_export = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
+}
elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL')
{
$sql.=" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'";
@@ -253,6 +278,14 @@ if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
if (strlen(trim($search_current_account))) {
$sql .= natural_search("p.accountancy_code_buy", $search_current_account);
}
+} elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ if (strlen(trim($search_current_account))) {
+ $sql .= natural_search("p.accountancy_code_buy_intra", $search_current_account);
+ }
+} elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ if (strlen(trim($search_current_account))) {
+ $sql .= natural_search("p.accountancy_code_buy_export", $search_current_account);
+ }
} elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
if (strlen(trim($search_current_account))) {
$sql .= natural_search("p.accountancy_code_sell", $search_current_account);
@@ -356,6 +389,13 @@ if ($result)
print "\n";
print '
' . $langs->trans('OptionModeProductBuy') . ' ';
print ''.$langs->trans('OptionModeProductBuyDesc')." \n";
+ if ($mysoc->isInEEC())
+ {
+ print ' ' . $langs->trans('OptionModeProductBuyIntra') . ' ';
+ print '' . $langs->trans('OptionModeProductBuyDesc') . " \n";
+ }
+ print ' ' . $langs->trans('OptionModeProductBuyExport') . ' ';
+ print ''.$langs->trans('OptionModeProductBuyDesc')." \n";
print "\n";
print '
';
@@ -386,7 +426,7 @@ if ($result)
print ''.$form->selectyesno('search_onsell', $search_onsell, 1, false, 1).' ';
}
// On buy
- elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
+ elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY' || $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
print ''.$form->selectyesno('search_onpurchase', $search_onpurchase, 1, false, 1).' ';
}
// Current account
@@ -416,10 +456,16 @@ if ($result)
} elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
$fieldtosortaccount="p.accountancy_code_sell_export";
- } else {
- if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
+ print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
$fieldtosortaccount="p.accountancy_code_buy";
- }
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
+ $fieldtosortaccount="p.accountancy_code_buy_intra";
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
+ $fieldtosortaccount="p.accountancy_code_buy_export";
+ }
print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], $fieldtosortaccount, "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("AssignDedicatedAccountingAccount");
$clickpitco=$form->showCheckAddButtons('checkforselect', 1);
@@ -482,11 +528,40 @@ if ($result)
// Purchases
if ($obj->product_type == 0) {
- $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
- $compta_prodbuy_id = $aarowid_prodbuy;
- } else {
- $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
- $compta_prodbuy_id = $aarowid_servbuy;
+ if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_prodbuy;
+ }
+ elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_prodbuy_intra;
+ }
+ elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_prodbuy_export;
+ }
+ else {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_servbuy;
+ }
+ }
+ else {
+ if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_prodbuy;
+ }
+ elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_prodbuy_intra;
+ }
+ elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_prodbuy_export;
+ }
+ else {
+ $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+ $compta_prodbuy_id = $aarowid_servbuy;
+ }
}
print '';
@@ -509,7 +584,7 @@ if ($result)
if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT')
print ''.$product_static->getLibStatut(3, 0).' ';
- if ($accounting_product_mode == 'ACCOUNTANCY_BUY')
+ if ($accounting_product_mode == 'ACCOUNTANCY_BUY' || $accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT')
print ''.$product_static->getLibStatut(3, 1).' ';
// Current accounting account
@@ -517,6 +592,12 @@ if ($result)
if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
print length_accountg($obj->accountancy_code_buy);
if ($obj->accountancy_code_buy && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ print length_accountg($obj->accountancy_code_buy_intra);
+ if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ print length_accountg($obj->accountancy_code_buy_export);
+ if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
} elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
print length_accountg($obj->accountancy_code_sell);
if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
@@ -540,6 +621,26 @@ if ($result)
if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
print '';
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
+ // Accounting account buy intra (In EEC)
+ print '';
+ //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
+ if (empty($defaultvalue)) $defaultvalue=$compta_prodbuy_intra;
+ $codesell=length_accountg($obj->accountancy_code_buy_intra);
+ //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
+ if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
+ print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
+ print ' ';
+ } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
+ // Accounting account buy export (Out of EEC)
+ print '';
+ //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
+ if (empty($defaultvalue)) $defaultvalue=$compta_prodbuy_export;
+ $codesell=length_accountg($obj->accountancy_code_buy_export);
+ //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
+ if (! empty($obj->aaid)) $defaultvalue = ''; // Do not suggest default new value is code is already valid
+ print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1);
+ print ' ';
} elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
// Accounting account sell
print '';
diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php
index 3bc44698029..3d32694218d 100644
--- a/htdocs/accountancy/supplier/index.php
+++ b/htdocs/accountancy/supplier/index.php
@@ -119,8 +119,9 @@ if ($action == 'validatehistory') {
// Supplier Invoice Lines (must be same request than into page list.php for manual binding)
$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.accountancy_code_buy as code_buy, p.tva_tx as tva_tx_prod,";
- $sql .= " aa.rowid as aarowid,";
+ $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type,";
+ $sql .= " p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export, p.tva_tx as tva_tx_prod,";
+ $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
$sql .= " co.code as country_code, co.label as country_label,";
$sql .= " s.tva_intra";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
@@ -128,7 +129,9 @@ if ($action == 'validatehistory') {
$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";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$chartaccountcode."' AND aa.entity = ".$conf->entity;
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$chartaccountcode."' AND aa.entity = ".$conf->entity;
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON p.accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$chartaccountcode."' AND aa2.entity = ".$conf->entity;
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON p.accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$chartaccountcode."' AND aa3.entity = ".$conf->entity;
$sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
$sql .= " AND l.product_type <= 2";
@@ -157,16 +160,12 @@ if ($action == 'validatehistory') {
$suggestedaccountingaccountfor = '';
} else {
if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
- //$objp->code_buy_p = $objp->code_buy_intra;
- $objp->code_buy_p = $objp->code_buy;
- //$objp->aarowid_suggest = $objp->aarowid_intra;
- $objp->aarowid_suggest = $objp->aarowid;
+ $objp->code_buy_p = $objp->code_buy_intra;
+ $objp->aarowid_suggest = $objp->aarowid_intra;
$suggestedaccountingaccountfor = 'eec';
} else { // Foreign sale
- //$objp->code_buy_p = $objp->code_buy_export;
- $objp->code_buy_p = $objp->code_buy;
- //$objp->aarowid_suggest = $objp->aarowid_export;
- $objp->aarowid_suggest = $objp->aarowid;
+ $objp->code_buy_p = $objp->code_buy_export;
+ $objp->aarowid_suggest = $objp->aarowid_export;
$suggestedaccountingaccountfor = 'export';
}
}
diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php
index ecd41f2f9da..d7a650e1f3d 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -211,7 +211,8 @@ 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.accountancy_code_buy as code_buy, p.tva_tx as tva_tx_prod,";
-$sql .= " aa.rowid as aarowid,";
+$sql .= " p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
+$sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
$sql .= " co.code as country_code, co.label as country_label,";
$sql .= " s.tva_intra";
$parameters = array();
@@ -222,7 +223,9 @@ $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$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";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
-$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$chartaccountcode."' AND aa.entity = ".$conf->entity;
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$chartaccountcode."' AND aa.entity = ".$conf->entity;
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$chartaccountcode."' AND aa2.entity = ".$conf->entity;
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$chartaccountcode."' AND aa3.entity = ".$conf->entity;
$sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
$sql .= " AND l.product_type <= 2";
// Add search filter like
@@ -414,7 +417,6 @@ if ($result) {
// issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
$objp->code_buy_l = '';
$objp->code_buy_p = '';
- $objp->aarowid_suggest = '';
$product_static->ref = $objp->product_ref;
$product_static->id = $objp->product_id;
@@ -426,28 +428,67 @@ if ($result) {
$facturefourn_static->type = $objp->type;
$code_buy_p_notset = '';
- $objp->aarowid_suggest = $objp->aarowid;
+ $objp->aarowid_suggest = ''; // Will be set later
+ $isBuyerInEEC = isInEEC($objp);
+
+ $suggestedaccountingaccountbydefaultfor = '';
if ($objp->type_l == 1) {
- $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : '');
- if ($objp->aarowid == '')
- $objp->aarowid_suggest = $aarowid_s;
+ if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
+ $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : '');
+ $suggestedaccountingaccountbydefaultfor = '';
+ } else {
+ if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
+ $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : '');
+ $suggestedaccountingaccountbydefaultfor = 'eec';
+ } else { // Foreign sale
+ $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : '');
+ $suggestedaccountingaccountbydefaultfor = 'export';
+ }
+ }
} elseif ($objp->type_l == 0) {
- $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : '');
- if ($objp->aarowid == '')
- $objp->aarowid_suggest = $aarowid_p;
+ if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
+ $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
+ $suggestedaccountingaccountbydefaultfor = '';
+ } else {
+ if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
+ $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : '');
+ $suggestedaccountingaccountbydefaultfor = 'eec';
+ } else {
+ $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : '');
+ $suggestedaccountingaccountbydefaultfor = 'export';
+ }
+ }
}
- if ($objp->code_buy_l == -1) $objp->code_buy_l = '';
+ if ($objp->code_sell_l == -1) $objp->code_sell_l = '';
- if (!empty($objp->code_buy)) {
- $objp->code_buy_p = $objp->code_buy; // Code on product
+ // Search suggested account for product/service
+ $suggestedaccountingaccountfor = '';
+ if (($objp->country_code == $mysoc->country_code) || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
+ $objp->code_buy_p = $objp->code_buy;
+ $objp->aarowid_suggest = $objp->aarowid;
+ $suggestedaccountingaccountfor = '';
+ } else {
+ if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
+ $objp->code_buy_p = $objp->code_buy_intra;
+ $objp->aarowid_suggest = $objp->aarowid_intra;
+ $suggestedaccountingaccountfor = 'eec';
+ } else { // Foreign sale
+ $objp->code_buy_p = $objp->code_buy_export;
+ $objp->aarowid_suggest = $objp->aarowid_export;
+ $suggestedaccountingaccountfor = 'export';
+ }
+ }
+
+ if (! empty($objp->code_buy_p)) {
+ // Value was defined previously
} else {
$code_buy_p_notset = 'color:orange';
}
if (empty($objp->code_buy_l) && empty($objp->code_buy_p)) $code_buy_p_notset = 'color:red';
- // $objp->code_buy_p is now code of product/service
- // $objp->code_buy_l is now default code of product/service
+ // $objp->code_sell_l is now default code of product/service
+ // $objp->code_sell_p is now code of product/service
print ' ';
@@ -520,6 +561,21 @@ if ($result) {
// Suggested accounting account
print '';
$suggestedid = $objp->aarowid_suggest;
+ if (empty($suggestedid) && empty($objp->code_buy_p) && ! empty($objp->code_buy_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC))
+ {
+ if (empty($accountingaccount_codetotid_cache[$objp->code_buy_l]))
+ {
+ $tmpaccount = new AccountingAccount($db);
+ $tmpaccount->fetch(0, $objp->code_buy_l, 1);
+ if ($tmpaccount->id > 0) {
+ $suggestedid = $tmpaccount->id;
+ }
+ $accountingaccount_codetotid_cache[$objp->code_buy_l] = $tmpaccount->id;
+ }
+ else {
+ $suggestedid = $accountingaccount_codetotid_cache[$objp->code_buy_l];
+ }
+ }
print $formaccounting->select_account($suggestedid, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
print ' ';
@@ -540,6 +596,9 @@ if ($result) {
} else {
print $db->error();
}
+if ($db->type == 'mysqli') {
+ $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
+}
// Add code to auto check the box when we select an account
print '