From 61547e3f824c8c68c9a800a8cace7c1857b14cfe Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 3 May 2019 14:08:20 +0200 Subject: [PATCH] NEW Manage account sell_intra & sell_export in page default product --- htdocs/accountancy/admin/productaccount.php | 141 +++++++++++++++----- htdocs/langs/en_US/accountancy.lang | 4 + 2 files changed, 111 insertions(+), 34 deletions(-) diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index 537eddfceb4..bd79791f709 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2019 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) @@ -111,6 +111,8 @@ if ($action == 'update') { $accounting_product_modes = array ( 'ACCOUNTANCY_SELL', + 'ACCOUNTANCY_SELL_INTRA', + 'ACCOUNTANCY_SELL_EXPORT', 'ACCOUNTANCY_BUY' ); @@ -158,6 +160,12 @@ if ($action == 'update') { if ($accounting_product_mode == 'ACCOUNTANCY_SELL') { $sql .= " SET accountancy_code_sell = " . $accounting->account_number; } + if ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') { + $sql .= " SET accountancy_code_sell_intra = " . $accounting->account_number; + } + if ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') { + $sql .= " SET accountancy_code_sell_export = " . $accounting->account_number; + } $sql .= " WHERE rowid = " . $productid; dol_syslog("/accountancy/admin/productaccount.php sql=" . $sql, LOG_DEBUG); @@ -193,15 +201,19 @@ $form = new FormAccounting($db); // so we need to get those default value rowid first $accounting = new AccountingAccount($db); // TODO: we should need to check if result is a really exist accountaccount rowid..... -$aarowid_servbuy = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1); -$aarowid_prodbuy = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1); -$aarowid_servsell = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1); -$aarowid_prodsell = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1); +$aarowid_servbuy = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1); +$aarowid_prodbuy = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1); +$aarowid_servsell = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1); +$aarowid_prodsell = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1); +$aarowid_prodsell_intra = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT, 1); +$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_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef")); -$aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); -$aacompta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); +$aacompta_servbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef")); +$aacompta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef")); +$aacompta_servsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); +$aacompta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); +$aacompta_prodsell_intra = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef")); +$aacompta_prodsell_export = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef")); llxHeader('', $langs->trans("ProductsBinding")); @@ -209,27 +221,45 @@ $pcgverid = $conf->global->CHARTOFACCOUNTS; $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version'); if (empty($pcgvercode)) $pcgvercode=$pcgverid; -$sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.accountancy_code_sell, p.accountancy_code_buy, p.tms, p.fk_product_type as product_type,"; +$sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.tms, p.fk_product_type as product_type,"; $sql.= " aa.rowid as aaid"; $sql.= " FROM " . MAIN_DB_PREFIX . "product as p"; $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 . "'"; } -else +elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') { $sql.=" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'"; } +elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') +{ + $sql.=" p.accountancy_code_sell_intra = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'"; +} +else +{ + $sql.=" p.accountancy_code_sell_intra = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'"; +} $sql.= ' WHERE p.entity IN ('.getEntity('product').')'; if ($accounting_product_mode == 'ACCOUNTANCY_BUY') { if (strlen(trim($search_current_account))) { $sql .= natural_search("p.accountancy_code_buy", $search_current_account); } -} else { +} elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') { if (strlen(trim($search_current_account))) { $sql .= natural_search("p.accountancy_code_sell", $search_current_account); } } +elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') { + if (strlen(trim($search_current_account))) { + $sql .= natural_search("p.accountancy_code_sell_intra", $search_current_account); + } +} +else { + if (strlen(trim($search_current_account))) { + $sql .= natural_search("p.accountancy_code_sell_export", $search_current_account); + } +} if ($search_current_account_valid == 'withoutvalidaccount') { $sql .= " AND aa.account_number IS NULL"; @@ -280,7 +310,7 @@ if ($result) if ($search_current_account > 0) $param.="&search_current_account=".urlencode($search_current_account); if ($search_current_account_valid && $search_current_account_valid != '-1') $param.="&search_current_account_valid=".urlencode($search_current_account_valid); if ($accounting_product_mode) $param.='&accounting_product_mode='.urlencode($accounting_product_mode); - + print '
'; if ($optioncss != '') print ''; print ''; @@ -301,9 +331,15 @@ if ($result) print ''; print '' . $langs->trans('Options') . '' . $langs->trans('Description') . ''; print "\n"; - print ' ' . $langs->trans('OptionModeProductSell') . ''; + print ' ' . $langs->trans('OptionModeProductSell') . ''; print ''.$langs->trans('OptionModeProductSellDesc'); print "\n"; + print ' ' . $langs->trans('OptionModeProductSellIntra') . ''; + print ''.$langs->trans('OptionModeProductSellIntraDesc'); + print "\n"; + print ' ' . $langs->trans('OptionModeProductSellExport') . ''; + print ''.$langs->trans('OptionModeProductSellExportDesc'); + print "\n"; print ' ' . $langs->trans('OptionModeProductBuy') . ''; print ''.$langs->trans('OptionModeProductBuyDesc')."\n"; print "\n"; @@ -318,9 +354,9 @@ if ($result) $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - $buttonsave = ''; - //print '
'.$buttonsave.'
'; - + $buttonsave = ''; + //print '
'.$buttonsave.'
'; + $texte=$langs->trans("ListOfProductsServices"); print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $buttonsave, $num, $nbtotalofrecords, '', 0, '', '', $limit); @@ -332,7 +368,7 @@ if ($result) print ''; if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print ''; // On sell - if ($accounting_product_mode == 'ACCOUNTANCY_SELL') print ''; + if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') print ''; // On buy if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print ''; // Current account @@ -352,10 +388,19 @@ if ($result) print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder); if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "p.description", "", $param, '', $sortfield, $sortorder); - if ($accounting_product_mode == 'ACCOUNTANCY_SELL') print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center '); - if ($accounting_product_mode == 'ACCOUNTANCY_BUY') print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center '); - if ($accounting_product_mode == 'ACCOUNTANCY_BUY') $fieldtosortaccount="p.accountancy_code_buy"; - else $fieldtosortaccount="p.accountancy_code_sell"; + if ($accounting_product_mode == 'ACCOUNTANCY_SELL') { + print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center '); + $fieldtosortaccount="p.accountancy_code_sell"; + } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') { + print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center '); + $fieldtosortaccount="p.accountancy_code_sell_intra"; + } 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 '); + $fieldtosortaccount="p.accountancy_code_buy"; + } print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], $fieldtosortaccount, "", $param, '', $sortfield, $sortorder); print_liste_field_titre("AssignDedicatedAccountingAccount"); $clickpitco=$form->showCheckAddButtons('checkforselect', 1); @@ -378,10 +423,16 @@ if ($result) $product_static->status = $obj->tosell; $product_static->status_buy = $obj->tobuy; - if ($obj->product_type == 0) { + if ($obj->product_type == 0 && $accounting_product_mode == 'ACCOUNTANCY_SELL') { $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); $compta_prodsell_id = $aarowid_prodsell; - } else { + } elseif ($obj->product_type == 0 && $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') { + $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef")); + $compta_prodsell_id = $aarowid_prodsell_intra; + } elseif ($obj->product_type == 0 && $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') { + $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef")); + $compta_prodsell_id = $aarowid_prodsell_export; + } else { $compta_prodsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); $compta_prodsell_id = $aarowid_servsell; } @@ -411,7 +462,7 @@ if ($result) print '' . nl2br(dol_trunc($obj->description, $trunclengh)) . ''; } - if ($accounting_product_mode == 'ACCOUNTANCY_SELL') + 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') @@ -422,12 +473,16 @@ 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")); - } - else - { - print length_accountg($obj->accountancy_code_sell); - 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")); + } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') { + print length_accountg($obj->accountancy_code_sell_intra); + if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount")); + } else { + print length_accountg($obj->accountancy_code_sell_export); + if ($obj->accountancy_code_sell_export && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount")); + } print ''; // Dedicated account @@ -441,7 +496,7 @@ 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 ''; - } else { + } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') { // Accounting account sell print ''; //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code @@ -451,7 +506,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_SELL_INTRA') { + // Accounting account sell intra (In EEC) + print ''; + //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code + if (empty($defaultvalue)) $defaultvalue=$compta_prodsell; + $codesell=length_accountg($obj->accountancy_code_sell_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 ''; + } else { + // Accounting account sell 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_prodsell; + $codesell=length_accountg($obj->accountancy_code_sell_export); + 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 ''; + } // Checkbox select print ''; @@ -462,7 +536,6 @@ if ($result) print ''; print ''; - // Example : Adding jquery code print '