--- /tmp/dsg/dolibarr/htdocs/compta/localtax/class/github_19.0.3_localtax.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/localtax/class/client_localtax.class.php @@ -53,25 +53,7 @@ - * @var int - */ - public $accountid; - - /** - * @var string - */ - public $fk_type; - - public $paymenttype; - - /** - * @var int - */ - public $rappro; - - - /** - * @var string local tax - */ - public $label; - - /** - * @var int ID - */ + * @var string local tax + */ + public $label; + + /** + * @var int ID + */ @@ -81,2 +63,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -86,2 +68,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -90 +72 @@ - /** + /** @@ -94,16 +76,16 @@ - */ - public function __construct($db) - { - $this->db = $db; - } - - - /** - * Create in database - * - * @param User $user User that create - * @return int Return integer <0 if KO, >0 if OK - */ - public function create($user) - { - global $conf, $langs; + */ + public function __construct($db) + { + $this->db = $db; + } + + + /** + * Create in database + * + * @param User $user User that create + * @return int <0 if KO, >0 if OK + */ + public function create($user) + { + global $conf, $langs; @@ -118 +100 @@ - // Insert request + // Insert request @@ -130,2 +112,2 @@ - $sql .= ") VALUES ("; - $sql .= " ".((int) $this->ltt).","; + $sql .= ") VALUES ("; + $sql .= " ".$this->ltt.","; @@ -143,16 +125,18 @@ - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); - - // Call trigger - $result = $this->call_trigger('LOCALTAX_CREATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - - if (!$error) { - $this->db->commit(); - return $this->id; - } else { + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); + + // Call trigger + $result = $this->call_trigger('LOCALTAX_CREATE', $user); + if ($result < 0) $error++; + // End call triggers + + if (!$error) + { + $this->db->commit(); + return $this->id; + } + else + { @@ -161,18 +145,20 @@ - } - } else { - $this->error = "Error ".$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - - /** - * Update database - * - * @param User $user User that modify - * @param int $notrigger 0=no, 1=yes (no update trigger) - * @return int Return integer <0 if KO, >0 if OK - */ - public function update(User $user, $notrigger = 0) - { - global $conf, $langs; + } + } + else + { + $this->error = "Error ".$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=no, 1=yes (no update trigger) + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = 0) + { + global $conf, $langs; @@ -191 +177 @@ - $sql .= " localtaxtype=".((int) $this->ltt).","; + $sql .= " localtaxtype=".$this->ltt.","; @@ -201,37 +187,41 @@ - $sql .= " WHERE rowid=".((int) $this->id); - - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->error = "Error ".$this->db->lasterror(); - $error++; - } - - if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('LOCALTAX_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - if (!$error) { - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } - } - - - /** - * Load object in memory from database - * - * @param int $id Object id - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($id) - { - $sql = "SELECT"; + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + $this->error = "Error ".$this->db->lasterror(); + $error++; + } + + if (!$error && !$notrigger) + { + // Call trigger + $result = $this->call_trigger('LOCALTAX_MODIFY', $user); + if ($result < 0) $error++; + // End call triggers + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Load object in memory from database + * + * @param int $id Object id + * @return int <0 if KO, >0 if OK + */ + public function fetch($id) + { + global $langs; + $sql = "SELECT"; @@ -245 +235 @@ - $sql .= " t.note as note_private,"; + $sql .= " t.note,"; @@ -252 +242 @@ - $sql .= " FROM ".MAIN_DB_PREFIX."localtax as t"; + $sql .= " FROM ".MAIN_DB_PREFIX."localtax as t"; @@ -254,11 +244,13 @@ - $sql .= " WHERE t.rowid = ".((int) $id); - - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->ltt = $obj->localtaxtype; + $sql .= " WHERE t.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->ltt = $obj->localtaxtype; @@ -270,2 +262 @@ - $this->note = $obj->note_private; - $this->note_private = $obj->note_private; + $this->note = $obj->note; @@ -278,9 +269,11 @@ - } - $this->db->free($resql); - - return 1; - } else { - $this->error = "Error ".$this->db->lasterror(); - return -1; - } - } + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } @@ -293 +286 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -299,3 +292 @@ - if ($result < 0) { - return -1; - } + if ($result < 0) return -1; @@ -305,3 +296,3 @@ - $sql .= " WHERE rowid=".((int) $this->id); - - dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -309 +300,2 @@ - if (!$resql) { + if (!$resql) + { @@ -327 +319 @@ - global $user; + global $user; @@ -344,44 +336,48 @@ - /** - * Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de localtax, non ? - * - * @param int $year Year - * @return int ??? - */ - public function solde($year = 0) - { - $reglee = $this->localtax_sum_reglee($year); - - $payee = $this->localtax_sum_payee($year); - $collectee = $this->localtax_sum_collectee($year); - - $solde = $reglee - ($collectee - $payee); - - return $solde; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Total de la localtax des factures emises par la societe. - * - * @param int $year Year - * @return int ??? - */ - public function localtax_sum_collectee($year = 0) - { - // phpcs:enable - $sql = "SELECT sum(f.localtax) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.paye = 1"; - if ($year) { - $sql .= " AND f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, 'gmt'))."' AND '".$this->db->idate(dol_get_last_day($year, 1, 'gmt'))."'"; - } - - $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $ret = $obj->amount; - $this->db->free($result); - return $ret; - } else { - $this->db->free($result); + /** + * Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de localtax, non ? + * + * @param int $year Year + * @return int ??? + */ + public function solde($year = 0) + { + $reglee = $this->localtax_sum_reglee($year); + + $payee = $this->localtax_sum_payee($year); + $collectee = $this->localtax_sum_collectee($year); + + $solde = $reglee - ($collectee - $payee); + + return $solde; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Total de la localtax des factures emises par la societe. + * + * @param int $year Year + * @return int ??? + */ + public function localtax_sum_collectee($year = 0) + { + // phpcs:enable + $sql = "SELECT sum(f.localtax) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1"; + if ($year) + { + $sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $ret = $obj->amount; + $this->db->free($result); + return $ret; + } + else + { + $this->db->free($result); @@ -389,33 +385,83 @@ - } - } else { - print $this->db->lasterror(); - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Total of localtax paid in invoice - * - * @param int $year Year - * @return int ??? - */ - public function localtax_sum_payee($year = 0) - { - // phpcs:enable - - $sql = "SELECT sum(f.total_localtax) as total_localtax"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - if ($year) { - $sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, 'gmt'))."' AND '".$this->db->idate(dol_get_last_day($year, 1, 'gmt'))."'"; - } - - $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $ret = $obj->total_localtax; - $this->db->free($result); - return $ret; - } else { - $this->db->free($result); + } + } + else + { + print $this->db->lasterror(); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * localtax payed + * + * @param int $year Year + * @return int ??? + */ + public function localtax_sum_payee($year = 0) + { + // phpcs:enable + + $sql = "SELECT sum(f.total_localtax) as total_localtax"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + if ($year) + { + $sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $ret = $obj->total_localtax; + $this->db->free($result); + return $ret; + } + else + { + $this->db->free($result); + return 0; + } + } + else + { + print $this->db->lasterror(); + return -1; + } + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * localtax payed + * Total de la localtax payed + * + * @param int $year Year + * @return int ??? + */ + public function localtax_sum_reglee($year = 0) + { + // phpcs:enable + + $sql = "SELECT sum(f.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f"; + if ($year) + { + $sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' "; + } + + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $ret = $obj->amount; + $this->db->free($result); + return $ret; + } + else + { + $this->db->free($result); @@ -423,46 +469,13 @@ - } - } else { - print $this->db->lasterror(); - return -1; - } - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Total of localtax paid - * - * @param int $year Year - * @return int ??? - */ - public function localtax_sum_reglee($year = 0) - { - // phpcs:enable - - $sql = "SELECT sum(f.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."localtax as f"; - if ($year) { - $sql .= " WHERE f.datev BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, 'gmt'))."' AND '".$this->db->idate(dol_get_last_day($year, 1, 'gmt'))."'"; - } - - $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $ret = $obj->amount; - $this->db->free($result); - return $ret; - } else { - $this->db->free($result); - return 0; - } - } else { - print $this->db->lasterror(); - return -1; - } - } - - - /** - * Add a payment of localtax - * + } + } + else + { + print $this->db->lasterror(); + return -1; + } + } + + + /** + * Add a payment of localtax + * @@ -470,11 +483,12 @@ - * @return int Return integer <0 if KO, rowid in localtax table if OK - */ - public function addPayment($user) - { - global $conf, $langs; - - $this->db->begin(); - - // Check parameters - $this->amount = price2num($this->amount); - if (!$this->label) { + * @return int <0 if KO, rowid in localtax table if OK + */ + public function addPayment($user) + { + global $conf, $langs; + + $this->db->begin(); + + // Check parameters + $this->amount = price2num($this->amount); + if (!$this->label) + { @@ -484,22 +498,21 @@ - if ($this->amount <= 0) { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); - return -4; - } - if (isModEnabled("banque") && (empty($this->accountid) || $this->accountid <= 0)) { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); - return -5; - } - if (isModEnabled("banque") && (empty($this->paymenttype) || $this->paymenttype <= 0)) { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); - return -5; - } - - // Insertion dans table des paiement localtax - $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax (localtaxtype, datep, datev, amount"; - if ($this->note) { - $sql .= ", note"; - } - if ($this->label) { - $sql .= ", label"; - } - $sql .= ", fk_user_creat, fk_bank"; + if ($this->amount <= 0) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); + return -4; + } + if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); + return -5; + } + if (!empty($conf->banque->enabled) && (empty($this->paymenttype) || $this->paymenttype <= 0)) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); + return -5; + } + + // Insertion dans table des paiement localtax + $sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax (localtaxtype, datep, datev, amount"; + if ($this->note) $sql .= ", note"; + if ($this->label) $sql .= ", label"; + $sql .= ", fk_user_creat, fk_bank"; @@ -507,10 +520,6 @@ - $sql .= " VALUES (".$this->ltt.", '".$this->db->idate($this->datep)."',"; - $sql .= "'".$this->db->idate($this->datev)."',".$this->amount; - if ($this->note) { - $sql .= ", '".$this->db->escape($this->note)."'"; - } - if ($this->label) { - $sql .= ", '".$this->db->escape($this->label)."'"; - } - $sql .= ", ".((int) $user->id).", NULL"; - $sql .= ")"; + $sql .= " VALUES (".$this->ltt.", '".$this->db->idate($this->datep)."',"; + $sql .= "'".$this->db->idate($this->datev)."',".$this->amount; + if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'"; + if ($this->label) $sql .= ", '".$this->db->escape($this->label)."'"; + $sql .= ", ".((int) $user->id).", NULL"; + $sql .= ")"; @@ -519,10 +528,13 @@ - $result = $this->db->query($sql); - if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); // TODO devrait s'appeler paiementlocaltax - if ($this->id > 0) { - $ok = 1; - if (isModEnabled("banque")) { - // Insertion dans llx_bank - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - - $acc = new Account($this->db); + $result = $this->db->query($sql); + if ($result) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); // TODO devrait s'appeler paiementlocaltax + if ($this->id > 0) + { + $ok = 1; + if (!empty($conf->banque->enabled)) + { + // Insertion dans llx_bank + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); @@ -530,10 +542,11 @@ - if ($result <= 0) { - dol_print_error($this->db); - } - - $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); - - // Update fk_bank into llx_localtax so we know the line of localtax used to generate the bank entry. - if ($bank_line_id > 0) { - $this->update_fk_bank($bank_line_id); - } else { + if ($result <= 0) dol_print_error($this->db); + + $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); + + // Mise a jour fk_bank dans llx_localtax. On connait ainsi la ligne de localtax qui a g�n�r� l'�criture bancaire + if ($bank_line_id > 0) + { + $this->update_fk_bank($bank_line_id); + } + else + { @@ -544,9 +557,11 @@ - // Mise a jour liens - $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/localtax/card.php?id=', "(VATPayment)", "payment_vat"); - if ($result < 0) { - $this->error = $acc->error; - $ok = 0; - } - } - - if ($ok) { + // Mise a jour liens + $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/localtax/card.php?id=', "(VATPayment)", "payment_vat"); + if ($result < 0) + { + $this->error = $acc->error; + $ok = 0; + } + } + + if ($ok) + { @@ -555 +570,3 @@ - } else { + } + else + { @@ -559,19 +576,23 @@ - } else { - $this->error = $this->db->lasterror(); - $this->db->rollback(); - return -2; - } - } else { - $this->error = $this->db->lasterror(); - $this->db->rollback(); - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Update the link betwen localtax payment and the line into llx_bank - * - * @param int $id Id bank account - * @return int Return integer <0 if KO, >0 if OK - */ + } + else + { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Update the link betwen localtax payment and the line into llx_bank + * + * @param int $id Id bank account + * @return int <0 if KO, >0 if OK + */ @@ -580,3 +601,3 @@ - // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'localtax SET fk_bank = '.((int) $id); - $sql .= ' WHERE rowid = '.((int) $this->id); + // phpcs:enable + $sql = 'UPDATE '.MAIN_DB_PREFIX.'localtax SET fk_bank = '.$id; + $sql .= ' WHERE rowid = '.$this->id; @@ -586 +607,3 @@ - } else { + } + else + { @@ -607 +630 @@ - $link = ''; + $link = ''; @@ -612,9 +635,3 @@ - if ($withpicto) { - $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); - } - if ($withpicto && $withpicto != 2) { - $result .= ' '; - } - if ($withpicto != 2) { - $result .= $link.$this->ref.$linkend; - } + if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); + if ($withpicto && $withpicto != 2) $result .= ' '; + if ($withpicto != 2) $result .= $link.$this->ref.$linkend; @@ -625 +642 @@ - * Return the label of the status + * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) @@ -627,2 +644,2 @@ - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle @@ -635,3 +652,3 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a given status + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne @@ -639,52 +656,11 @@ - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status - */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable - //global $langs; - - return ''; - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'label')) { - $return .= ' | '.$this->label.''; - } - if (property_exists($this, 'datev')) { - $return .= '
'.$langs->trans("DateEnd").' : '.dol_print_date($this->db->jdate($this->datev), 'day').''; - } - if (property_exists($this, 'datep')) { - $return .= '
'.$langs->trans("DatePayment", '', '', '', '', 5).' : '.dol_print_date($this->db->jdate($this->datep), 'day').''; - } - if (property_exists($this, 'amount')) { - $return .= '
'.$langs->trans("Amount").' : '.price($this->amount).''; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } + * @param int $status Statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable + global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage + + return ''; + }