NEW : rewrite bind accountancy code finding on customer invoice
This commit is contained in:
parent
ce64ebc167
commit
2fdc6d9461
@ -195,7 +195,7 @@ if (empty($reshook)) {
|
|||||||
} elseif ($action == 'enable' && $permissiontoadd) {
|
} elseif ($action == 'enable' && $permissiontoadd) {
|
||||||
if ($accounting->fetch($id)) {
|
if ($accounting->fetch($id)) {
|
||||||
$mode = GETPOST('mode', 'int');
|
$mode = GETPOST('mode', 'int');
|
||||||
$result = $accounting->account_activate($id, $mode);
|
$result = $accounting->accountActivate($id, $mode);
|
||||||
}
|
}
|
||||||
$action = 'update';
|
$action = 'update';
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
|
|||||||
@ -26,6 +26,9 @@
|
|||||||
* \brief File of class to manage accounting accounts
|
* \brief File of class to manage accounting accounts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||||
/**
|
/**
|
||||||
* Class to manage accounting accounts
|
* Class to manage accounting accounts
|
||||||
*/
|
*/
|
||||||
@ -140,6 +143,11 @@ class AccountingAccount extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $reconcilable;
|
public $reconcilable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array cache array
|
||||||
|
*/
|
||||||
|
private $accountingaccount_codetotid_cache = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -153,75 +161,6 @@ class AccountingAccount extends CommonObject
|
|||||||
$this->next_prev_filter = 'fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; // Used to add a filter in Form::showrefnav method
|
$this->next_prev_filter = 'fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; // Used to add a filter in Form::showrefnav method
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load record in memory
|
|
||||||
*
|
|
||||||
* @param int $rowid Id
|
|
||||||
* @param string $account_number Account number
|
|
||||||
* @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active char of account
|
|
||||||
* @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC' (better and faster than previous parameter if you have chart of account code).
|
|
||||||
* @return int <0 if KO, 0 if not found, Id of record if OK and found
|
|
||||||
*/
|
|
||||||
public function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount = '')
|
|
||||||
{
|
|
||||||
global $conf;
|
|
||||||
|
|
||||||
if ($rowid || $account_number) {
|
|
||||||
$sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable";
|
|
||||||
$sql .= ", ca.label as category_label";
|
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as a";
|
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
|
|
||||||
$sql .= " WHERE";
|
|
||||||
if ($rowid) {
|
|
||||||
$sql .= " a.rowid = ".(int) $rowid;
|
|
||||||
} elseif ($account_number) {
|
|
||||||
$sql .= " a.account_number = '".$this->db->escape($account_number)."'";
|
|
||||||
$sql .= " AND a.entity = ".$conf->entity;
|
|
||||||
}
|
|
||||||
if (!empty($limittocurrentchart)) {
|
|
||||||
$sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid='.$this->db->escape($conf->global->CHARTOFACCOUNTS).')';
|
|
||||||
}
|
|
||||||
if (!empty($limittoachartaccount)) {
|
|
||||||
$sql .= " AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount)."'";
|
|
||||||
}
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
if ($result) {
|
|
||||||
$obj = $this->db->fetch_object($result);
|
|
||||||
|
|
||||||
if ($obj) {
|
|
||||||
$this->id = $obj->rowid;
|
|
||||||
$this->rowid = $obj->rowid;
|
|
||||||
$this->ref = $obj->account_number;
|
|
||||||
$this->datec = $obj->datec;
|
|
||||||
$this->tms = $obj->tms;
|
|
||||||
$this->fk_pcg_version = $obj->fk_pcg_version;
|
|
||||||
$this->pcg_type = $obj->pcg_type;
|
|
||||||
$this->account_number = $obj->account_number;
|
|
||||||
$this->account_parent = $obj->account_parent;
|
|
||||||
$this->label = $obj->label;
|
|
||||||
$this->labelshort = $obj->labelshort;
|
|
||||||
$this->account_category = $obj->fk_accounting_category;
|
|
||||||
$this->account_category_label = $obj->category_label;
|
|
||||||
$this->fk_user_author = $obj->fk_user_author;
|
|
||||||
$this->fk_user_modif = $obj->fk_user_modif;
|
|
||||||
$this->active = $obj->active;
|
|
||||||
$this->status = $obj->active;
|
|
||||||
$this->reconcilable = $obj->reconcilable;
|
|
||||||
|
|
||||||
return $this->id;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->error = "Error ".$this->db->lasterror();
|
|
||||||
$this->errors[] = "Error ".$this->db->lasterror();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert new accounting account in chart of accounts
|
* Insert new accounting account in chart of accounts
|
||||||
*
|
*
|
||||||
@ -364,38 +303,6 @@ class AccountingAccount extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check usage of accounting code
|
|
||||||
*
|
|
||||||
* @return int <0 if KO, >0 if OK
|
|
||||||
*/
|
|
||||||
public function checkUsage()
|
|
||||||
{
|
|
||||||
global $langs;
|
|
||||||
|
|
||||||
$sql = "(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facturedet";
|
|
||||||
$sql .= " WHERE fk_code_ventilation=".$this->id.")";
|
|
||||||
$sql .= "UNION";
|
|
||||||
$sql .= " (SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facture_fourn_det";
|
|
||||||
$sql .= " WHERE fk_code_ventilation=".$this->id.")";
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::checkUsage sql=".$sql, LOG_DEBUG);
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
|
|
||||||
if ($resql) {
|
|
||||||
$num = $this->db->num_rows($resql);
|
|
||||||
if ($num > 0) {
|
|
||||||
$this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse');
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->error = $this->db->lasterror();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete object in database
|
* Delete object in database
|
||||||
*
|
*
|
||||||
@ -441,6 +348,38 @@ class AccountingAccount extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check usage of accounting code
|
||||||
|
*
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
public function checkUsage()
|
||||||
|
{
|
||||||
|
global $langs;
|
||||||
|
|
||||||
|
$sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet";
|
||||||
|
$sql .= " WHERE fk_code_ventilation=" . $this->id . ")";
|
||||||
|
$sql .= "UNION";
|
||||||
|
$sql .= " (SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det";
|
||||||
|
$sql .= " WHERE fk_code_ventilation=" . $this->id . ")";
|
||||||
|
|
||||||
|
dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG);
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
|
if ($resql) {
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
if ($num > 0) {
|
||||||
|
$this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse');
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return clicable name (with picto eventually)
|
* Return clicable name (with picto eventually)
|
||||||
*
|
*
|
||||||
@ -465,7 +404,8 @@ class AccountingAccount extends CommonObject
|
|||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
$url = ''; $labelurl = '';
|
$url = '';
|
||||||
|
$labelurl = '';
|
||||||
if (empty($option) || $option == 'ledger') {
|
if (empty($option) || $option == 'ledger') {
|
||||||
$url = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode($this->account_number) . '&search_accountancy_code_end=' . urlencode($this->account_number);
|
$url = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode($this->account_number) . '&search_accountancy_code_end=' . urlencode($this->account_number);
|
||||||
$labelurl = $langs->trans("ShowAccountingAccountInLedger");
|
$labelurl = $langs->trans("ShowAccountingAccountInLedger");
|
||||||
@ -620,7 +560,7 @@ class AccountingAccount extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
|
||||||
/**
|
/**
|
||||||
* Account activated
|
* Account activated
|
||||||
*
|
*
|
||||||
@ -628,7 +568,7 @@ class AccountingAccount extends CommonObject
|
|||||||
* @param int $mode 0=field active, 1=field reconcilable
|
* @param int $mode 0=field active, 1=field reconcilable
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function account_activate($id, $mode = 0)
|
public function accountActivate($id, $mode = 0)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
@ -642,7 +582,7 @@ class AccountingAccount extends CommonObject
|
|||||||
$sql .= " SET " . $fieldtouse . " = '1'";
|
$sql .= " SET " . $fieldtouse . " = '1'";
|
||||||
$sql .= " WHERE rowid = " . $this->db->escape($id);
|
$sql .= " WHERE rowid = " . $this->db->escape($id);
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::account_activate ".$fieldtouse." sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this) . "::accountActivate " . $fieldtouse . " sql=" . $sql, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
@ -654,7 +594,6 @@ class AccountingAccount extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne le libelle du statut d'un user (actif, inactif)
|
* Retourne le libelle du statut d'un user (actif, inactif)
|
||||||
*
|
*
|
||||||
@ -718,4 +657,229 @@ class AccountingAccount extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Suggest accounting accounts to bind
|
||||||
|
*
|
||||||
|
* @param Societe $thirdparty Societe Object seller or Buyers
|
||||||
|
* @param Product $product Product object sell or buy
|
||||||
|
* @param Facture $facture Facture
|
||||||
|
* @param FactureLigne $factureDet Facture Det
|
||||||
|
* @param array $accountingAccount array of Account account
|
||||||
|
*
|
||||||
|
* @return array Accounting accounts suggested
|
||||||
|
*/
|
||||||
|
public function getAccountingCodeToBind(Societe $thirdparty, Product $product, Facture $facture, FactureLigne $factureDet, $accountingAccount = array())
|
||||||
|
{
|
||||||
|
global $mysoc, $conf;
|
||||||
|
global $hookmanager;
|
||||||
|
|
||||||
|
// Instantiate hooks for external modules
|
||||||
|
$hookmanager->initHooks(array('accoutancyBindingCalculation'));
|
||||||
|
|
||||||
|
// Execute hook accoutancyBindingCalculation
|
||||||
|
$parameters = array('thirdparty' => $thirdparty, 'product' => $product, 'facture' => $facture, 'factureDet' => $factureDet ,'accountingAccount'=>$accountingAccount);
|
||||||
|
$reshook = $hookmanager->executeHooks('accoutancyBindingCalculation', $parameters); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
|
if (empty($reshook)) {
|
||||||
|
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
|
||||||
|
$isBuyerInEEC = isInEEC($thirdparty);
|
||||||
|
$isSellerInEEC = isInEEC($mysoc);
|
||||||
|
$code_sell_l = '';
|
||||||
|
$code_sell_p = '';
|
||||||
|
$code_sell_t = '';
|
||||||
|
$suggestedid = '';
|
||||||
|
|
||||||
|
// Level 1: Search suggested default account for product/service
|
||||||
|
$suggestedaccountingaccountbydefaultfor = '';
|
||||||
|
if ($factureDet->product_type == 1) {
|
||||||
|
if ($thirdparty->country_code == $mysoc->country_code || empty($thirdparty->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = '';
|
||||||
|
} else {
|
||||||
|
if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) { // European intravat sale, but with a VAT
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'eecwithvat';
|
||||||
|
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($thirdparty->tva_intra)) { // European intravat sale, without VAT intra community number
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
|
||||||
|
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'eec';
|
||||||
|
} else { // Foreign sale
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'export';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($factureDet->product_type == 0) {
|
||||||
|
if ($thirdparty->country_code == $mysoc->country_code || empty($thirdparty->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = '';
|
||||||
|
} else {
|
||||||
|
if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) { // European intravat sale, but with a VAT
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'eecwithvat';
|
||||||
|
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($thirdparty->tva_intra)) { // European intravat sale, without VAT intra community number
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
|
||||||
|
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'eec';
|
||||||
|
} else {
|
||||||
|
$code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : '');
|
||||||
|
$suggestedaccountingaccountbydefaultfor = 'export';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($code_sell_l == -1) {
|
||||||
|
$code_sell_l = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level 2: Search suggested account for product/service (similar code exists in page index.php to make automatic binding)
|
||||||
|
$suggestedaccountingaccountfor = '';
|
||||||
|
if (($thirdparty->country_code == $mysoc->country_code) || empty($thirdparty->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
|
||||||
|
$code_sell_p = $product->accountancy_code_sell;
|
||||||
|
$suggestedid = $accountingAccount['dom'];
|
||||||
|
$suggestedaccountingaccountfor = '';
|
||||||
|
} else {
|
||||||
|
if ($isSellerInEEC && $isBuyerInEEC && $factureDet->tva_tx != 0) { // European intravat sale, but with VAT
|
||||||
|
$code_sell_p = $product->accountancy_code_sell;
|
||||||
|
$suggestedid = $accountingAccount['dom'];
|
||||||
|
$suggestedaccountingaccountfor = 'eecwithvat';
|
||||||
|
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($thirdparty->tva_intra)) { // European intravat sale, without VAT intra community number
|
||||||
|
$code_sell_p = $product->accountancy_code_sell;
|
||||||
|
$suggestedid = $accountingAccount['dom']; // There is a doubt for this case. Is it an error on vat or we just forgot to fill vat number ?
|
||||||
|
$suggestedaccountingaccountfor = 'eecwithoutvatnumber';
|
||||||
|
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
|
||||||
|
$code_sell_p = $product->accountancy_code_sell_intra;
|
||||||
|
$suggestedid = $accountingAccount['intra'];
|
||||||
|
$suggestedaccountingaccountfor = 'eec';
|
||||||
|
} else { // Foreign sale
|
||||||
|
$code_sell_p = $product->accountancy_code_sell_export;
|
||||||
|
$suggestedid = $accountingAccount['export'];
|
||||||
|
$suggestedaccountingaccountfor = 'export';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding)
|
||||||
|
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
|
||||||
|
if (!empty($thirdparty->code_compta)) {
|
||||||
|
$code_sell_t = $thirdparty->code_compta;
|
||||||
|
$suggestedid = $accountingAccount['thirdparty'];
|
||||||
|
$suggestedaccountingaccountfor = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manage Deposit
|
||||||
|
if ($factureDet->desc == "(DEPOSIT)") {
|
||||||
|
$accountdeposittoventilated = new self($this->db);
|
||||||
|
$result = $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
|
||||||
|
if ($result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$code_sell_l = $accountdeposittoventilated->ref;
|
||||||
|
$suggestedid = $accountdeposittoventilated->rowid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($suggestedid) && empty($code_sell_p) && !empty($code_sell_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) {
|
||||||
|
if (empty($this->accountingaccount_codetotid_cache[$code_sell_l])) {
|
||||||
|
$tmpaccount = new self($this->db);
|
||||||
|
$result = $tmpaccount->fetch(0, $code_sell_l, 1);
|
||||||
|
if ($result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ($tmpaccount->id > 0) {
|
||||||
|
$suggestedid = $tmpaccount->id;
|
||||||
|
}
|
||||||
|
$this->accountingaccount_codetotid_cache[$code_sell_l] = $tmpaccount->id;
|
||||||
|
} else {
|
||||||
|
$suggestedid = $this->accountingaccount_codetotid_cache[$code_sell_l];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (is_array($hookmanager->resArray) && !empty($hookmanager->resArray)) {
|
||||||
|
return $hookmanager->resArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array(
|
||||||
|
'suggestedaccountingaccountbydefaultfor' => $suggestedaccountingaccountbydefaultfor,
|
||||||
|
'suggestedaccountingaccountfor' => $suggestedaccountingaccountfor,
|
||||||
|
'suggestedid' => $suggestedid,
|
||||||
|
'code_sell_l' => $code_sell_l,
|
||||||
|
'code_sell_p' => $code_sell_p,
|
||||||
|
'code_sell_t' => $code_sell_t,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load record in memory
|
||||||
|
*
|
||||||
|
* @param int $rowid Id
|
||||||
|
* @param string $account_number Account number
|
||||||
|
* @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active char of account
|
||||||
|
* @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC' (better and faster than previous parameter if you have chart of account code).
|
||||||
|
* @return int <0 if KO, 0 if not found, Id of record if OK and found
|
||||||
|
*/
|
||||||
|
public function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount = '')
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
if ($rowid || $account_number) {
|
||||||
|
$sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable";
|
||||||
|
$sql .= ", ca.label as category_label";
|
||||||
|
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a";
|
||||||
|
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
|
||||||
|
$sql .= " WHERE";
|
||||||
|
if ($rowid) {
|
||||||
|
$sql .= " a.rowid = " . (int) $rowid;
|
||||||
|
} elseif ($account_number) {
|
||||||
|
$sql .= " a.account_number = '" . $this->db->escape($account_number) . "'";
|
||||||
|
$sql .= " AND a.entity = " . $conf->entity;
|
||||||
|
}
|
||||||
|
if (!empty($limittocurrentchart)) {
|
||||||
|
$sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $this->db->escape($conf->global->CHARTOFACCOUNTS) . ')';
|
||||||
|
}
|
||||||
|
if (!empty($limittoachartaccount)) {
|
||||||
|
$sql .= " AND a.fk_pcg_version = '" . $this->db->escape($limittoachartaccount) . "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if ($result) {
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
|
if ($obj) {
|
||||||
|
$this->id = $obj->rowid;
|
||||||
|
$this->rowid = $obj->rowid;
|
||||||
|
$this->ref = $obj->account_number;
|
||||||
|
$this->datec = $obj->datec;
|
||||||
|
$this->tms = $obj->tms;
|
||||||
|
$this->fk_pcg_version = $obj->fk_pcg_version;
|
||||||
|
$this->pcg_type = $obj->pcg_type;
|
||||||
|
$this->account_number = $obj->account_number;
|
||||||
|
$this->account_parent = $obj->account_parent;
|
||||||
|
$this->label = $obj->label;
|
||||||
|
$this->labelshort = $obj->labelshort;
|
||||||
|
$this->account_category = $obj->fk_accounting_category;
|
||||||
|
$this->account_category_label = $obj->category_label;
|
||||||
|
$this->fk_user_author = $obj->fk_user_author;
|
||||||
|
$this->fk_user_modif = $obj->fk_user_modif;
|
||||||
|
$this->active = $obj->active;
|
||||||
|
$this->status = $obj->active;
|
||||||
|
$this->reconcilable = $obj->reconcilable;
|
||||||
|
|
||||||
|
return $this->id;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->error = "Error " . $this->db->lasterror();
|
||||||
|
$this->errors[] = "Error " . $this->db->lasterror();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ $massaction = GETPOST('massaction', 'alpha');
|
|||||||
$show_files = GETPOST('show_files', 'int');
|
$show_files = GETPOST('show_files', 'int');
|
||||||
$confirm = GETPOST('confirm', 'alpha');
|
$confirm = GETPOST('confirm', 'alpha');
|
||||||
$toselect = GETPOST('toselect', 'array');
|
$toselect = GETPOST('toselect', 'array');
|
||||||
|
$optioncss = GETPOST('optioncss', 'alpha');
|
||||||
|
|
||||||
// Select Box
|
// Select Box
|
||||||
$mesCasesCochees = GETPOST('toselect', 'array');
|
$mesCasesCochees = GETPOST('toselect', 'array');
|
||||||
@ -96,6 +97,7 @@ if (!$sortorder) {
|
|||||||
$hookmanager->initHooks(array('accountancycustomerlist'));
|
$hookmanager->initHooks(array('accountancycustomerlist'));
|
||||||
|
|
||||||
$formaccounting = new FormAccounting($db);
|
$formaccounting = new FormAccounting($db);
|
||||||
|
$accountingAccount = new AccountingAccount($db);
|
||||||
|
|
||||||
$chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
|
$chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
|
||||||
|
|
||||||
@ -510,17 +512,17 @@ if ($result) {
|
|||||||
|
|
||||||
$thirdpartystatic = new Societe($db);
|
$thirdpartystatic = new Societe($db);
|
||||||
$facture_static = new Facture($db);
|
$facture_static = new Facture($db);
|
||||||
|
$facture_static_det = new FactureLigne($db);
|
||||||
$product_static = new Product($db);
|
$product_static = new Product($db);
|
||||||
|
|
||||||
$isSellerInEEC = isInEEC($mysoc);
|
|
||||||
|
|
||||||
$accountingaccount_codetotid_cache = array();
|
$accountingaccount_codetotid_cache = array();
|
||||||
|
|
||||||
while ($i < min($num_lines, $limit)) {
|
while ($i < min($num_lines, $limit)) {
|
||||||
$objp = $db->fetch_object($result);
|
$objp = $db->fetch_object($result);
|
||||||
|
|
||||||
$objp->code_sell_l = '';
|
$code_sell_l = '';
|
||||||
$objp->code_sell_p = '';
|
$code_sell_p = '';
|
||||||
|
|
||||||
$thirdpartystatic->id = $objp->socid;
|
$thirdpartystatic->id = $objp->socid;
|
||||||
$thirdpartystatic->name = $objp->name;
|
$thirdpartystatic->name = $objp->name;
|
||||||
@ -532,6 +534,8 @@ if ($result) {
|
|||||||
$thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
|
$thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
|
||||||
$thirdpartystatic->email = $objp->email;
|
$thirdpartystatic->email = $objp->email;
|
||||||
$thirdpartystatic->country_code = $objp->country_code;
|
$thirdpartystatic->country_code = $objp->country_code;
|
||||||
|
$thirdpartystatic->tva_intra = $objp->tva_intra;
|
||||||
|
$thirdpartystatic->code_compta = $objp->company_code_sell;
|
||||||
|
|
||||||
$product_static->ref = $objp->product_ref;
|
$product_static->ref = $objp->product_ref;
|
||||||
$product_static->id = $objp->product_id;
|
$product_static->id = $objp->product_id;
|
||||||
@ -545,158 +549,96 @@ if ($result) {
|
|||||||
$product_static->accountancy_code_buy = $objp->code_buy;
|
$product_static->accountancy_code_buy = $objp->code_buy;
|
||||||
$product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
|
$product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
|
||||||
$product_static->accountancy_code_buy_export = $objp->code_buy_export;
|
$product_static->accountancy_code_buy_export = $objp->code_buy_export;
|
||||||
|
$product_static->tva_tx = $objp->tva_tx_prod;
|
||||||
|
$product_static->tva_tx = $objp->tva_tx_prod;
|
||||||
|
|
||||||
$facture_static->ref = $objp->ref;
|
$facture_static->ref = $objp->ref;
|
||||||
$facture_static->id = $objp->facid;
|
$facture_static->id = $objp->facid;
|
||||||
$facture_static->type = $objp->ftype;
|
$facture_static->type = $objp->ftype;
|
||||||
|
$facture_static->datef = $objp->datef;
|
||||||
|
|
||||||
|
$facture_static_det->id = $objp->rowid;
|
||||||
|
$facture_static_det->total_ht = $objp->total_ht;
|
||||||
|
$facture_static_det->tva_tx = $objp->tva_tx_line;
|
||||||
|
$facture_static_det->vat_src_code = $objp->vat_src_code;
|
||||||
|
$facture_static_det->product_type = $objp->type_l;
|
||||||
|
$facture_static_det->desc = $objp->description;
|
||||||
|
|
||||||
|
$accoutinAccountArray = array(
|
||||||
|
'dom'=>$objp->aarowid,
|
||||||
|
'intra'=>$objp->aarowid_intra,
|
||||||
|
'export'=>$objp->aarowid_export,
|
||||||
|
'thirdparty' =>$objp->aarowid_thirdparty);
|
||||||
|
|
||||||
$code_sell_p_notset = '';
|
$code_sell_p_notset = '';
|
||||||
$code_sell_t_notset = '';
|
$code_sell_t_notset = '';
|
||||||
$objp->aarowid_suggest = ''; // Will be set later
|
|
||||||
|
|
||||||
$isBuyerInEEC = isInEEC($objp);
|
$return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $product_static, $facture_static, $facture_static_det, $accoutinAccountArray);
|
||||||
|
if (!is_array($return) && $return<0) {
|
||||||
// Level 1: Search suggested default account for product/service
|
setEventMessage($accountingAccount->error, 'errors');
|
||||||
$suggestedaccountingaccountbydefaultfor = '';
|
|
||||||
if ($objp->type_l == 1) {
|
|
||||||
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_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = '';
|
|
||||||
} else {
|
} else {
|
||||||
if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) { // European intravat sale, but with a VAT
|
$suggestedid=$return['suggestedid'];
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
|
$suggestedaccountingaccountfor=$return['suggestedaccountingaccountfor'];
|
||||||
$suggestedaccountingaccountbydefaultfor = 'eecwithvat';
|
$suggestedaccountingaccountbydefaultfor=$return['suggestedaccountingaccountbydefaultfor'];
|
||||||
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) { // European intravat sale, without VAT intra community number
|
$code_sell_l=$return['code_sell_l'];
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
|
$code_sell_p=$return['code_sell_p'];
|
||||||
$suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
|
$code_sell_t=$return['code_sell_t'];
|
||||||
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
|
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = 'eec';
|
|
||||||
} else { // Foreign sale
|
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = 'export';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($objp->type_l == 0) {
|
|
||||||
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_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = '';
|
|
||||||
} else {
|
|
||||||
if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) { // European intravat sale, but with a VAT
|
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = 'eecwithvat';
|
|
||||||
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) { // European intravat sale, without VAT intra community number
|
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
|
|
||||||
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
|
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = 'eec';
|
|
||||||
} else {
|
|
||||||
$objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : '');
|
|
||||||
$suggestedaccountingaccountbydefaultfor = 'export';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($objp->code_sell_l == -1) {
|
|
||||||
$objp->code_sell_l = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Level 2: Search suggested account for product/service (similar code exists in page index.php to make automatic binding)
|
if (!empty($code_sell_p)) {
|
||||||
$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_sell_p = $objp->code_sell;
|
|
||||||
$objp->aarowid_suggest = $objp->aarowid;
|
|
||||||
$suggestedaccountingaccountfor = '';
|
|
||||||
} else {
|
|
||||||
if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) { // European intravat sale, but with VAT
|
|
||||||
$objp->code_sell_p = $objp->code_sell;
|
|
||||||
$objp->aarowid_suggest = $objp->aarowid;
|
|
||||||
$suggestedaccountingaccountfor = 'eecwithvat';
|
|
||||||
} elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) { // European intravat sale, without VAT intra community number
|
|
||||||
$objp->code_sell_p = $objp->code_sell;
|
|
||||||
$objp->aarowid_suggest = $objp->aarowid; // There is a doubt for this case. Is it an error on vat or we just forgot to fill vat number ?
|
|
||||||
$suggestedaccountingaccountfor = 'eecwithoutvatnumber';
|
|
||||||
} elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
|
|
||||||
$objp->code_sell_p = $objp->code_sell_intra;
|
|
||||||
$objp->aarowid_suggest = $objp->aarowid_intra;
|
|
||||||
$suggestedaccountingaccountfor = 'eec';
|
|
||||||
} else { // Foreign sale
|
|
||||||
$objp->code_sell_p = $objp->code_sell_export;
|
|
||||||
$objp->aarowid_suggest = $objp->aarowid_export;
|
|
||||||
$suggestedaccountingaccountfor = 'export';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding)
|
|
||||||
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
|
|
||||||
if (!empty($objp->company_code_sell)) {
|
|
||||||
$objp->code_sell_t = $objp->company_code_sell;
|
|
||||||
$objp->aarowid_suggest = $objp->aarowid_thirdparty;
|
|
||||||
$suggestedaccountingaccountfor = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manage Deposit
|
|
||||||
if ($objp->description == "(DEPOSIT)") {
|
|
||||||
$accountdeposittoventilated = new AccountingAccount($db);
|
|
||||||
$accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
|
|
||||||
$objp->code_sell_l = $accountdeposittoventilated->ref;
|
|
||||||
$objp->aarowid_suggest = $accountdeposittoventilated->rowid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($objp->code_sell_p)) {
|
|
||||||
// Value was defined previously
|
// Value was defined previously
|
||||||
} else {
|
} else {
|
||||||
$code_sell_p_notset = 'color:orange';
|
$code_sell_p_notset = 'color:orange';
|
||||||
}
|
}
|
||||||
if (empty($objp->code_sell_l) && empty($objp->code_sell_p)) {
|
if (empty($code_sell_l) && empty($code_sell_p)) {
|
||||||
$code_sell_p_notset = 'color:red';
|
$code_sell_p_notset = 'color:red';
|
||||||
}
|
}
|
||||||
if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
|
if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
|
||||||
$code_sell_p_notset = 'color:orange';
|
$code_sell_p_notset = 'color:orange';
|
||||||
}
|
}
|
||||||
|
|
||||||
// $objp->code_sell_l is now default code of product/service
|
// $code_sell_l is now default code of product/service
|
||||||
// $objp->code_sell_p is now code of product/service
|
// $code_sell_p is now code of product/service
|
||||||
// $objp->code_sell_t is now code of thirdparty
|
// $code_sell_t is now code of thirdparty
|
||||||
|
|
||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven">';
|
||||||
|
|
||||||
// Line id
|
// Line id
|
||||||
print '<td>'.$objp->rowid.'</td>';
|
print '<td>'.$facture_static_det->id.'</td>';
|
||||||
|
|
||||||
// Ref Invoice
|
// Ref Invoice
|
||||||
print '<td class="nowraponall">'.$facture_static->getNomUrl(1).'</td>';
|
print '<td class="nowraponall">'.$facture_static->getNomUrl(1).'</td>';
|
||||||
|
|
||||||
print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
|
print '<td class="center">'.dol_print_date($db->jdate($facture_static->datef), 'day').'</td>';
|
||||||
|
|
||||||
// Ref Product
|
// Ref Product
|
||||||
print '<td class="tdoverflowmax150">';
|
print '<td class="tdoverflowmax150">';
|
||||||
if ($product_static->id > 0) {
|
if ($product_static->id > 0) {
|
||||||
print $product_static->getNomUrl(1);
|
print $product_static->getNomUrl(1);
|
||||||
}
|
}
|
||||||
if ($objp->product_label) {
|
if ($product_static->label) {
|
||||||
print '<br><span class="opacitymedium small">'.$objp->product_label.'</span>';
|
print '<br><span class="opacitymedium small">'.$product_static->label.'</span>';
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
print '<td class="tdoverflowonsmartphone small">';
|
print '<td class="tdoverflowonsmartphone small">';
|
||||||
$text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
|
$text = dolGetFirstLineOfText(dol_string_nohtmltag($facture_static_det->desc));
|
||||||
$trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
|
$trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
|
||||||
print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
|
print $form->textwithtooltip(dol_trunc($text, $trunclength), $facture_static_det->desc);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td class="nowrap right">';
|
print '<td class="nowrap right">';
|
||||||
print price($objp->total_ht);
|
print price($facture_static_det->total_ht);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Vat rate
|
// Vat rate
|
||||||
if ($objp->vat_tx_l != $objp->vat_tx_p) {
|
$code_vat_differ='';
|
||||||
|
if ($product_static->tva_tx !== $facture_static_det->tva_tx) {
|
||||||
$code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
|
$code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
|
||||||
}
|
}
|
||||||
print '<td style="'.$code_vat_differ.'" class="right">';
|
print '<td style="'.$code_vat_differ.'" class="right">';
|
||||||
print vatrate($objp->tva_tx_line.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : ''));
|
print vatrate($facture_static_det->tva_tx.($facture_static_det->vat_src_code ? ' ('.$facture_static_det->vat_src_code.')' : ''));
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Thirdparty
|
// Thirdparty
|
||||||
@ -704,27 +646,27 @@ if ($result) {
|
|||||||
|
|
||||||
// Country
|
// Country
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
|
$labelcountry = ($thirdpartystatic->country_code && ($langs->trans("Country".$thirdpartystatic->country_code) != "Country".$thirdpartystatic->country_code)) ? $langs->trans("Country".$thirdpartystatic->country_code) : $objp->country_label;
|
||||||
print $labelcountry;
|
print $labelcountry;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// VAT Num
|
// VAT Num
|
||||||
print '<td>'.$objp->tva_intra.'</td>';
|
print '<td>'.$thirdpartystatic->tva_intra.'</td>';
|
||||||
|
|
||||||
// Found accounts
|
// Found accounts
|
||||||
print '<td class="small">';
|
print '<td class="small">';
|
||||||
$s = '1. '.(($objp->type_l == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': ';
|
$s = '1. '.(($facture_static_det->product_type == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': ';
|
||||||
$shelp = '';
|
$shelp = '';
|
||||||
if ($suggestedaccountingaccountbydefaultfor == 'eec') {
|
if ($suggestedaccountingaccountbydefaultfor == 'eec') {
|
||||||
$shelp .= $langs->trans("SaleEEC");
|
$shelp .= $langs->trans("SaleEEC");
|
||||||
} elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
|
} elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
|
||||||
$shelp .= $langs->trans("SaleExport");
|
$shelp .= $langs->trans("SaleExport");
|
||||||
}
|
}
|
||||||
$s .= ($objp->code_sell_l > 0 ? length_accountg($objp->code_sell_l) : '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>');
|
$s .= ($code_sell_l > 0 ? length_accountg($code_sell_l) : '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>');
|
||||||
print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
|
print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
|
||||||
if ($objp->product_id > 0) {
|
if ($product_static->id > 0) {
|
||||||
print '<br>';
|
print '<br>';
|
||||||
$s = '2. '.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
|
$s = '2. '.(($facture_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
|
||||||
$shelp = ''; $ttype = 'help';
|
$shelp = ''; $ttype = 'help';
|
||||||
if ($suggestedaccountingaccountfor == 'eec') {
|
if ($suggestedaccountingaccountfor == 'eec') {
|
||||||
$shelp = $langs->trans("SaleEEC");
|
$shelp = $langs->trans("SaleEEC");
|
||||||
@ -736,12 +678,12 @@ if ($result) {
|
|||||||
} elseif ($suggestedaccountingaccountfor == 'export') {
|
} elseif ($suggestedaccountingaccountfor == 'export') {
|
||||||
$shelp = $langs->trans("SaleExport");
|
$shelp = $langs->trans("SaleExport");
|
||||||
}
|
}
|
||||||
$s .= (empty($objp->code_sell_p) ? '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($objp->code_sell_p));
|
$s .= (empty($code_sell_p) ? '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($code_sell_p));
|
||||||
print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
|
print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
|
||||||
} else {
|
} else {
|
||||||
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
|
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
|
||||||
print '<br>';
|
print '<br>';
|
||||||
$s = '2. '.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
|
$s = '2. '.(($facture_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
|
||||||
$shelp = '';
|
$shelp = '';
|
||||||
$s .= $langs->trans("NotDefined");
|
$s .= $langs->trans("NotDefined");
|
||||||
print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
|
print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
|
||||||
@ -749,29 +691,16 @@ if ($result) {
|
|||||||
}
|
}
|
||||||
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
|
if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
|
||||||
print '<br>';
|
print '<br>';
|
||||||
$s = '3. '.(($objp->type_l == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")).': ';
|
$s = '3. '.(($facture_static_det->product_type == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")).': ';
|
||||||
$shelp = '';
|
$shelp = '';
|
||||||
$s .= ($objp->code_sell_t > 0 ? length_accountg($objp->code_sell_t) : '<span style="'.$code_sell_t_notset.'">'.$langs->trans("NotDefined").'</span>');
|
$s .= ($code_sell_t > 0 ? length_accountg($code_sell_t) : '<span style="'.$code_sell_t_notset.'">'.$langs->trans("NotDefined").'</span>');
|
||||||
print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
|
print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Suggested accounting account
|
// Suggested accounting account
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$suggestedid = $objp->aarowid_suggest;
|
print $formaccounting->select_account($suggestedid, 'codeventil'.$facture_static_det->id, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
|
||||||
if (empty($suggestedid) && empty($objp->code_sell_p) && !empty($objp->code_sell_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) {
|
|
||||||
if (empty($accountingaccount_codetotid_cache[$objp->code_sell_l])) {
|
|
||||||
$tmpaccount = new AccountingAccount($db);
|
|
||||||
$tmpaccount->fetch(0, $objp->code_sell_l, 1);
|
|
||||||
if ($tmpaccount->id > 0) {
|
|
||||||
$suggestedid = $tmpaccount->id;
|
|
||||||
}
|
|
||||||
$accountingaccount_codetotid_cache[$objp->code_sell_l] = $tmpaccount->id;
|
|
||||||
} else {
|
|
||||||
$suggestedid = $accountingaccount_codetotid_cache[$objp->code_sell_l];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print $formaccounting->select_account($suggestedid, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
|
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Column with checkbox
|
// Column with checkbox
|
||||||
@ -780,7 +709,7 @@ if ($result) {
|
|||||||
if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') {
|
if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') {
|
||||||
$ischecked = 0;
|
$ischecked = 0;
|
||||||
}
|
}
|
||||||
print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="'.$objp->rowid."_".$i.'"'.($ischecked ? "checked" : "").'/>';
|
print '<input type="checkbox" class="flat checkforselect checkforselect'.$facture_static_det->id.'" name="toselect[]" value="'.$facture_static_det->id."_".$i.'"'.($ischecked ? "checked" : "").'/>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user