diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index f1245854d80..9d675ff85fd 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -28,6 +28,7 @@ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/tva/class/tva.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/paymentsocialcontribution.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); $langs->load("compta"); @@ -58,7 +59,7 @@ if (! $sortorder) $sortorder="DESC"; $tva_static = new Tva($db); $socialcontrib=new ChargeSociales($db); -$payment_sc_static=new PaiementCharge($db); +$payment_sc_static=new PaymentSocialContribution($db); llxHeader('',$langs->trans("TaxAndDividendsArea")); diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 29c0973ce63..b05008c2648 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -77,7 +77,7 @@ class Paiement $sql.= ' WHERE p.fk_paiement = c.id'; $sql.= ' AND p.rowid = '.$id; - dol_syslog("Paiement::fetch sql=".$sql); + dol_syslog(get_class($this)."::fetch sql=".$sql); $result = $this->db->query($sql); if ($result) @@ -148,7 +148,7 @@ class Paiement $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)"; $sql.= " VALUES ('".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".addslashes($this->note)."', ".$user->id.")"; - dol_syslog("Paiement::Create insert paiement sql=".$sql); + dol_syslog(get_class($this)."::Create insert paiement sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -164,18 +164,18 @@ class Paiement $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)'; $sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\')'; - dol_syslog('Paiement::Create Amount line '.$key.' insert paiement_facture sql='.$sql); + dol_syslog(get_class($this).'::Create Amount line '.$key.' insert paiement_facture sql='.$sql); $resql=$this->db->query($sql); if (! $resql) { $this->error=$this->db->lasterror(); - dol_syslog('Paiement::Create insert paiement_facture error='.$this->error, LOG_ERR); + dol_syslog(get_class($this).'::Create insert paiement_facture error='.$this->error, LOG_ERR); $error++; } } else { - dol_syslog('Paiement::Create Amount line '.$key.' not a number. We discard it.'); + dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.'); } } @@ -192,7 +192,7 @@ class Paiement else { $this->error=$this->db->error(); - dol_syslog('Paiement::Create insert paiement error='.$this->error, LOG_ERR); + dol_syslog(get_class($this).'::Create insert paiement error='.$this->error, LOG_ERR); $error++; } @@ -424,7 +424,7 @@ class Paiement $sql = 'UPDATE llx_paiement set fk_bank = '.$id_bank; $sql.= ' WHERE rowid = '.$this->id; - dol_syslog('Paiement::update_fk_bank sql='.$sql); + dol_syslog(get_class($this).'::update_fk_bank sql='.$sql); $result = $this->db->query($sql); if ($result) { @@ -445,7 +445,7 @@ class Paiement { $sql = 'UPDATE '.MAIN_DB_PREFIX.'paiement SET statut = 1 WHERE rowid = '.$this->id; - dol_syslog('Paiement::valide sql='.$sql); + dol_syslog(get_class($this).'::valide sql='.$sql); $result = $this->db->query($sql); if ($result) { @@ -453,7 +453,7 @@ class Paiement } else { - dol_syslog('Paiement::valide Error -1'); + dol_syslog(get_class($this).'::valide Error -1'); return -1; } } @@ -469,7 +469,7 @@ class Paiement $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as c'; $sql.= ' WHERE c.rowid = '.$id; - dol_syslog('Paiement::info sql='.$sql); + dol_syslog(get_class($this).'::info sql='.$sql); $result = $this->db->query($sql); if ($result) @@ -531,7 +531,7 @@ class Paiement else { $this->error=$this->db->error(); - dol_syslog('Paiement::getBillsArray Error '.$this->error.' - sql='.$sql); + dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' - sql='.$sql); return -1; } } diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 6a7b4b161fb..5ec1599c2cb 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -24,8 +24,9 @@ */ require('../main.inc.php'); -include_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); -include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/paymentsocialcontribution.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); $langs->load("bills"); @@ -86,8 +87,8 @@ if ($_POST["action"] == 'add_paiement') $db->begin(); - // Creation de la ligne paiement - $paiement = new PaiementCharge($db); + // Create a line of payments + $paiement = new PaymentSocialContribution($db); $paiement->chid = $chid; $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Tableau de montant diff --git a/htdocs/compta/payment_sc/fiche.php b/htdocs/compta/payment_sc/fiche.php index 30a5c3ec9a9..a7ef50a5186 100644 --- a/htdocs/compta/payment_sc/fiche.php +++ b/htdocs/compta/payment_sc/fiche.php @@ -28,7 +28,8 @@ */ require('../../main.inc.php'); -include_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/paymentsocialcontribution.class.php"); require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'); require_once(DOL_DOCUMENT_ROOT."/includes/modules/facture/modules_facture.php"); if ($conf->banque->enabled) require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); @@ -56,7 +57,7 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && { $db->begin(); - $paiement = new PaiementCharge($db); + $paiement = new PaymentSocialContribution($db); $paiement->fetch($_REQUEST['id']); $result = $paiement->delete($user); if ($result > 0) @@ -77,7 +78,7 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && { $db->begin(); - $paiement = new PaiementCharge($db); + $paiement = new PaymentSocialContribution($db); $paiement->id = $_REQUEST['id']; if ($paiement->valide() > 0) { @@ -116,7 +117,9 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && llxHeader(); -$paiement = new PaiementCharge($db); +$socialcontrib=new ChargeSociales($db); +$paiement = new PaymentSocialContribution($db); + $result=$paiement->fetch($_GET['id']); if ($result <= 0) { @@ -230,6 +233,7 @@ if ($resql) print '
'; print ''; print ''; + print ''; print ''; print ''; print ''; @@ -240,24 +244,28 @@ if ($resql) { $var=True; - $socialcontribstatic=new ChargeSociales($db); - while ($i < $num) { $objp = $db->fetch_object($resql); + $var=!$var; print ''; + // Ref print '\n"; + // Type + print '\n"; + // Label print ''; // Expected to pay print ''; // Status - print ''; + print ''; // Amount payed print ''; print "\n"; diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 7ccf87cf909..c60feca2b7a 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -168,7 +168,7 @@ if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->cha * View */ -llxHeader(); +llxHeader('',$langs->trans("SocialContribution")); $html = new Form($db); @@ -247,11 +247,9 @@ if ($_GET["action"] == 'create') if ($chid > 0) { $cha = new ChargeSociales($db); + $result=$cha->fetch($chid); - /* - * Charge - */ - if ($cha->fetch($chid) > 0) + if ($result > 0) { if ($mesg) print $mesg.'
'; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 942fe3582fb..63c86df8550 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -316,7 +316,7 @@ class ChargeSociales extends CommonObject } /** - * \brief Return amount aof payments already done + * \brief Return amount of payments already done * \return int Amount of payment already done, <0 if KO */ function getSommePaiement() @@ -343,560 +343,4 @@ class ChargeSociales extends CommonObject } } - -/** \class PaiementCharge - * \brief Classe permettant la gestion des paiements des charges - */ -class PaiementCharge extends CommonObject -{ - var $db; //!< To store db handler - var $error; //!< To return error code (or message) - var $errors=array(); //!< To return several error codes (or messages) - var $element='paiementcharge'; //!< Id that identify managed objects - var $table_element='paiementcharge'; //!< Name of table without prefix where object is stored - - var $id; - var $ref; - - var $fk_charge; - var $datec=''; - var $tms=''; - var $datep=''; - var $amount; - var $fk_typepaiement; - var $num_paiement; - var $note; - var $fk_bank; - var $fk_user_creat; - var $fk_user_modif; - - /** - * \brief Constructor - * \param DB Database handler - */ - function PaiementCharge($DB) - { - $this->db = $DB; - return 1; - } - - /** - * \brief Creation d'un paiement de charge sociale dans la base - * \param user Utilisateur qui cree le paiement - * \return int <0 si KO, id du paiement cree si OK - */ - function create($user) - { - global $conf, $langs; - $error=0; - - // Validation parametres - if (! $this->datepaye) - { - $this->error='ErrorBadValueForParameters'; - return -1; - } - - $now=dol_now(); - - // Clean parameters - if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); - if (isset($this->amount)) $this->amount=trim($this->amount); - if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); - if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); - if (isset($this->note)) $this->note=trim($this->note); - if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); - if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); - if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); - - $this->db->begin(); - - $total=0; - foreach ($this->amounts as $key => $value) - { - $amount = price2num(trim($value), 'MT'); - $total += $amount; - } - - if ($total != 0) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,"; - $sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)"; - $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."', "; - $sql.= " '".$this->db->idate($this->datepaye)."', "; - $sql.= price2num($total); - $sql.= ", ".$this->paiementtype.", '".addslashes($this->num_paiement)."', '".addslashes($this->note)."', ".$user->id.","; - $sql.= "0)"; - - dol_syslog("PaiementCharge::create sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge"); - } - else - { - $error++; - } - - } - - if ($total != 0 && ! $error) - { - $this->db->commit(); - return $this->id; - } - else - { - $this->error=$this->db->error(); - dol_syslog("PaiementCharges::create ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } - - /** - * \brief Load object in memory from database - * \param id id object - * \return int <0 if KO, >0 if OK - */ - function fetch($id) - { - global $langs; - $sql = "SELECT"; - $sql.= " t.rowid,"; - $sql.= " t.fk_charge,"; - $sql.= " t.datec,"; - $sql.= " t.tms,"; - $sql.= " t.datep,"; - $sql.= " t.amount,"; - $sql.= " t.fk_typepaiement,"; - $sql.= " t.num_paiement,"; - $sql.= " t.note,"; - $sql.= " t.fk_bank,"; - $sql.= " t.fk_user_creat,"; - $sql.= " t.fk_user_modif,"; - $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; - $sql.= ' b.fk_account'; - $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; - $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; - - dol_syslog(get_class($this)."::fetch sql=".$sql, 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->fk_charge = $obj->fk_charge; - $this->datec = $this->db->jdate($obj->datec); - $this->tms = $this->db->jdate($obj->tms); - $this->datep = $this->db->jdate($obj->datep); - $this->amount = $obj->amount; - $this->fk_typepaiement = $obj->fk_typepaiement; - $this->num_paiement = $obj->num_paiement; - $this->note = $obj->note; - $this->fk_bank = $obj->fk_bank; - $this->fk_user_creat = $obj->fk_user_creat; - $this->fk_user_modif = $obj->fk_user_modif; - - $this->type_code = $obj->type_code; - $this->type_libelle = $obj->type_libelle; - - $this->bank_account = $obj->fk_account; - $this->bank_line = $obj->fk_bank; - } - $this->db->free($resql); - - return 1; - } - else - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); - return -1; - } - } - - - /** - * \brief Update database - * \param user User that modify - * \param notrigger 0=launch triggers after, 1=disable triggers - * \return int <0 if KO, >0 if OK - */ - function update($user=0, $notrigger=0) - { - global $conf, $langs; - $error=0; - - // Clean parameters - - if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); - if (isset($this->amount)) $this->amount=trim($this->amount); - if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); - if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); - if (isset($this->note)) $this->note=trim($this->note); - if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); - if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); - if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); - - - - // Check parameters - // Put here code to add control on parameters values - - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET"; - - $sql.= " fk_charge=".(isset($this->fk_charge)?$this->fk_charge:"null").","; - $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; - $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; - $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; - $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; - $sql.= " fk_typepaiement=".(isset($this->fk_typepaiement)?$this->fk_typepaiement:"null").","; - $sql.= " num_paiement=".(isset($this->num_paiement)?"'".addslashes($this->num_paiement)."'":"null").","; - $sql.= " note=".(isset($this->note)?"'".addslashes($this->note)."'":"null").","; - $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; - $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; - $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; - - - $sql.= " WHERE rowid=".$this->id; - - $this->db->begin(); - - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. - - //// Call triggers - //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; - } - } - - - /** - * \brief Delete object in database - * \param user User that delete - * \param notrigger 0=launch triggers after, 1=disable triggers - * \return int <0 if KO, >0 if OK - */ - function delete($user, $notrigger=0) - { - global $conf, $langs; - $error=0; - - $this->db->begin(); - - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; - $sql.= " WHERE type='payment_sc' AND url_id=".$this->id; - - dol_syslog(get_class($this)."::delete sql=".$sql); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - } - - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge"; - $sql.= " WHERE rowid=".$this->id; - - dol_syslog(get_class($this)."::delete sql=".$sql); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - } - - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. - - //// Call triggers - //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } - } - - // Commit or rollback - if ($error) - { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } - $this->db->rollback(); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; - } - } - - - - /** - * \brief Load an object from its id and create a new one in database - * \param fromid Id of object to clone - * \return int New id of clone - */ - function createFromClone($fromid) - { - global $user,$langs; - - $error=0; - - $object=new Paiementcharge($this->db); - - $this->db->begin(); - - // Load source object - $object->fetch($fromid); - $object->id=0; - $object->statut=0; - - // Clear fields - // ... - - // Create clone - $result=$object->create($user); - - // Other options - if ($result < 0) - { - $this->error=$object->error; - $error++; - } - - if (! $error) - { - - - - } - - // End - if (! $error) - { - $this->db->commit(); - return $object->id; - } - else - { - $this->db->rollback(); - return -1; - } - } - - - /** - * \brief Initialise object with example values - * \remarks id must be 0 if object instance is a specimen. - */ - function initAsSpecimen() - { - $this->id=0; - - $this->fk_charge=''; - $this->datec=''; - $this->tms=''; - $this->datep=''; - $this->amount=''; - $this->fk_typepaiement=''; - $this->num_paiement=''; - $this->note=''; - $this->fk_bank=''; - $this->fk_user_creat=''; - $this->fk_user_modif=''; - - - } - - - /** - * A record into bank for payment with links between this bank record and invoices of payment. - * All payment properties must have been set first like after a call to create(). - * @param user Object of user making payment - * @param mode 'payment_sc' - * @param label Label to use in bank record - * @param accountid Id of bank account to do link with - * @param emetteur_nom Name of transmitter - * @param emetteur_banque Name of bank - * @return int <0 if KO, >0 if OK - */ - function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) - { - global $conf; - - $error=0; - - if ($conf->banque->enabled) - { - require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); - - $acc = new Account($this->db); - $acc->fetch($accountid); - - $total=$this->total; - if ($mode == 'payment_sc') $total=-$total; - - // Insert payment into llx_bank - $bank_line_id = $acc->addline($this->datepaye, - $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") - $label, - $total, - $this->num_paiement, - '', - $user, - $emetteur_nom, - $emetteur_banque); - - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) - { - $result=$this->update_fk_bank($bank_line_id); - if ($result <= 0) - { - $error++; - dol_print_error($this->db); - } - - // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction - $url=''; - if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='; - if ($url) - { - $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); - if ($result <= 0) - { - $error++; - dol_print_error($this->db); - } - } - - // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) - $linkaddedforthirdparty=array(); - foreach ($this->amounts as $key => $value) - { - if ($mode == 'payment_sc') - { - $socialcontrib = new ChargeSociales($this->db); - $socialcontrib->fetch($key); - $result=$acc->add_url_line($bank_line_id, $socialcontrib->id, - DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); - if ($result <= 0) dol_print_error($this->db); - } - } - } - else - { - $this->error=$acc->error; - $error++; - } - } - - if (! $error) - { - return 1; - } - else - { - return -1; - } - } - - - /** - * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee - * \param id_bank Id de la banque - * \return int >0 si OK, <=0 si KO - */ - function update_fk_bank($id_bank) - { - $sql = "UPDATE llx_paiementcharge set fk_bank = ".$id_bank." where rowid = ".$this->id; - - dol_syslog("PaiementCharge::update_fk_bank sql=".$sql); - $result = $this->db->query($sql); - if ($result) - { - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog("PaiementCharges::update_fk_bank ".$this->error, LOG_ERR); - return 0; - } - } - - /** - * \brief Renvoie nom clicable (avec eventuellement le picto) - * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - * \param maxlen Longueur max libelle - * \return string Chaine avec URL - */ - function getNomUrl($withpicto=0,$maxlen=0) - { - global $langs; - - $result=''; - - if (empty($this->ref)) $this->ref=$this->lib; - - $lien = ''; - $lienfin=''; - - if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$lienfin.' '); - if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; - return $result; - } -} - - ?> diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php new file mode 100644 index 00000000000..c31a1d546b7 --- /dev/null +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -0,0 +1,585 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/compta/sociales/class/chargesociales.class.php + * \ingroup facture + * \brief Fichier de la classe des charges sociales + * \version $Id$ + */ + +require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); + + +/** \class PaymentSocialContribution + * \brief Class to manage payments of social contributions + */ +class PaymentSocialContribution extends CommonObject +{ + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + var $element='paiementcharge'; //!< Id that identify managed objects + var $table_element='paiementcharge'; //!< Name of table without prefix where object is stored + + var $id; + var $ref; + + var $fk_charge; + var $datec=''; + var $tms=''; + var $datep=''; + var $amount; + var $fk_typepaiement; + var $num_paiement; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + + /** + * \brief Constructor + * \param DB Database handler + */ + function PaymentSocialContribution($DB) + { + $this->db = $DB; + return 1; + } + + /** + * \brief Creation d'un paiement de charge sociale dans la base + * \param user Utilisateur qui cree le paiement + * \return int <0 si KO, id du paiement cree si OK + */ + function create($user) + { + global $conf, $langs; + $error=0; + + // Validation parametres + if (! $this->datepaye) + { + $this->error='ErrorBadValueForParameters'; + return -1; + } + + $now=dol_now(); + + // Clean parameters + if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); + if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + $this->db->begin(); + + $total=0; + foreach ($this->amounts as $key => $value) + { + $amount = price2num(trim($value), 'MT'); + $total += $amount; + } + + if ($total != 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,"; + $sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)"; + $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."', "; + $sql.= " '".$this->db->idate($this->datepaye)."', "; + $sql.= price2num($total); + $sql.= ", ".$this->paiementtype.", '".addslashes($this->num_paiement)."', '".addslashes($this->note)."', ".$user->id.","; + $sql.= "0)"; + + dol_syslog(get_class($this)."::create sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge"); + } + else + { + $error++; + } + + } + + if ($total != 0 && ! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + + /** + * \brief Load object in memory from database + * \param id id object + * \return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.fk_charge,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount,"; + $sql.= " t.fk_typepaiement,"; + $sql.= " t.num_paiement,"; + $sql.= " t.note,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; + $sql.= ' b.fk_account'; + $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."paiementcharge as t)"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; + $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepaiement = pt.id"; + + dol_syslog(get_class($this)."::fetch sql=".$sql, 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->fk_charge = $obj->fk_charge; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount = $obj->amount; + $this->fk_typepaiement = $obj->fk_typepaiement; + $this->num_paiement = $obj->num_paiement; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_libelle = $obj->type_libelle; + + $this->bank_account = $obj->fk_account; + $this->bank_line = $obj->fk_bank; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + + /** + * \brief Update database + * \param user User that modify + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement=trim($this->fk_typepaiement); + if (isset($this->num_paiement)) $this->num_paiement=trim($this->num_paiement); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET"; + + $sql.= " fk_charge=".(isset($this->fk_charge)?$this->fk_charge:"null").","; + $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; + $sql.= " fk_typepaiement=".(isset($this->fk_typepaiement)?$this->fk_typepaiement:"null").","; + $sql.= " num_paiement=".(isset($this->num_paiement)?"'".addslashes($this->num_paiement)."'":"null").","; + $sql.= " note=".(isset($this->note)?"'".addslashes($this->note)."'":"null").","; + $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; + $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; + $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; + + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * \brief Delete object in database + * \param user User that delete + * \param notrigger 0=launch triggers after, 1=disable triggers + * \return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $this->db->begin(); + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; + $sql.= " WHERE type='payment_sc' AND url_id=".$this->id; + + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + + /** + * \brief Load an object from its id and create a new one in database + * \param fromid Id of object to clone + * \return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; + + $error=0; + + $object=new PaymentSocialContribution($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id=0; + $object->statut=0; + + // Clear fields + // ... + + // Create clone + $result=$object->create($user); + + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } + + if (! $error) + { + + + + } + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * \brief Initialise object with example values + * \remarks id must be 0 if object instance is a specimen. + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_charge=''; + $this->datec=''; + $this->tms=''; + $this->datep=''; + $this->amount=''; + $this->fk_typepaiement=''; + $this->num_paiement=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + + + } + + + /** + * A record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * @param user Object of user making payment + * @param mode 'payment_sc' + * @param label Label to use in bank record + * @param accountid Id of bank account to do link with + * @param emetteur_nom Name of transmitter + * @param emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) + { + global $conf; + + $error=0; + + if ($conf->banque->enabled) + { + require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total=$this->total; + if ($mode == 'payment_sc') $total=-$total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline($this->datepaye, + $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") + $label, + $total, + $this->num_paiement, + '', + $user, + $emetteur_nom, + $emetteur_banque); + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result=$this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + $url=''; + if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='; + if ($url) + { + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + + // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) + $linkaddedforthirdparty=array(); + foreach ($this->amounts as $key => $value) + { + if ($mode == 'payment_sc') + { + $socialcontrib = new ChargeSociales($this->db); + $socialcontrib->fetch($key); + $result=$acc->add_url_line($bank_line_id, $socialcontrib->id, + DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc'); + if ($result <= 0) dol_print_error($this->db); + } + } + } + else + { + $this->error=$acc->error; + $error++; + } + } + + if (! $error) + { + return 1; + } + else + { + return -1; + } + } + + + /** + * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee + * \param id_bank Id de la banque + * \return int >0 si OK, <=0 si KO + */ + function update_fk_bank($id_bank) + { + $sql = "UPDATE llx_paiementcharge set fk_bank = ".$id_bank." where rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_fk_bank sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + $this->error=$this->db->error(); + dol_syslog(get_class($this)."::update_fk_bank ".$this->error, LOG_ERR); + return 0; + } + } + + /** + * \brief Renvoie nom clicable (avec eventuellement le picto) + * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * \param maxlen Longueur max libelle + * \return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$maxlen=0) + { + global $langs; + + $result=''; + + if (empty($this->ref)) $this->ref=$this->lib; + + $lien = ''; + $lienfin=''; + + if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$lienfin.' '); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$lienfin; + return $result; + } +} + + +?>
'.$langs->trans('SocialContribution').''.$langs->trans('Type').''.$langs->trans('Label').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').'
'; - $socialcontribstatic->id=$objp->scid; - $socialcontribstatic->ref=$objp->scid; - $socialcontribstatic->lib=$objp->sc_type; - print $socialcontribstatic->getNomUrl(1); + $socialcontrib->fetch($objp->scid); + print $socialcontrib->getNomUrl(1); print "'; + print $socialcontrib->type_libelle; + /*print $socialcontrib->type;*/ + print "'.$objp->libelle.''.price($objp->sc_amount).''.$socialcontribstatic->LibStatut($objp->fk_statut,2).''.$socialcontrib->LibStatut($objp->fk_statut,2).''.price($objp->amount).'