diff --git a/ChangeLog b/ChangeLog index ee7f01a682c..610307c12d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -68,6 +68,7 @@ For users: - Fix: Better Postgresql compatibility. - Fix: Numbering module for invoices use same number for invoice and credit note if mask is same. +- Fix: Debug and clean withdraw module. For developers: - New: External modules can add tabs on agenda views. diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a8d0e384c5a..1717f7700c7 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2463,7 +2463,7 @@ else } print ''; - // Montants + // Amount print ''.$langs->trans('AmountHT').''; print ''.price($object->total_ht).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 5e5edc23b0f..f1a9bc1db79 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -75,42 +75,208 @@ if ($id > 0 || ! empty($ref)) $author->fetch($object->user_author); } - $head = facture_prepare_head($object); + $head = facture_prepare_head($object); dol_fiche_head($head, 'preview', $langs->trans("InvoiceCustomer"), 0, 'bill'); + $totalpaye = $object->getSommePaiement(); + /* * Facture */ print ''; - $rowspan=3; + $rowspan=3; // Reference print ''; - // Societe + // Societe print ''; print ''; print ''; - // Dates - print ''; - print ''; - print '"; + // Type + print ''; - print ''; - // Remise globale - print ''; - print ''; + // Relative and absolute discounts + $addabsolutediscount=' '.$langs->trans("AddGlobalDiscount").''; + $addcreditnote=' '.$langs->trans("AddCreditNote").''; + + print ''; + + // Dates + print ''; + print ''; + print ""; + + // Date payment term + print ''; + + // Conditions reglement + print ''; + print ''; + + // Mode de reglement + print ''; $nbrows=5; if ($conf->projet->enabled) $nbrows++; @@ -121,7 +287,7 @@ if ($id > 0 || ! empty($ref)) */ $objectref = dol_sanitizeFileName($object->ref); $dir_output = $conf->facture->dir_output . "/"; - $filepath = $dir_output . $objectref . "/"; + $filepath = $dir_output . $objectref . "/"; $file = $filepath . $objectref . ".pdf"; $filedetail = $filepath . $objectref . "-detail.pdf"; $relativepath = $objectref.'/'.$objectref.'.pdf'; @@ -164,15 +330,15 @@ if ($id > 0 || ! empty($ref)) // Conversion du PDF en image png si fichier png non existant if (! file_exists($fileimage) && ! file_exists($fileimagebis)) { - if (class_exists("Imagick")) - { - $ret = dol_convert_file($file); - if ($ret < 0) $error++; + if (class_exists("Imagick")) + { + $ret = dol_convert_file($file); + if ($ret < 0) $error++; } else { - $langs->load("other"); - print ''.$langs->trans("ErrorNoImagickReadimage").''; + $langs->load("other"); + print ''.$langs->trans("ErrorNoImagickReadimage").''; } } } @@ -182,19 +348,19 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - // Statut - print ''; + // Statut + print ''; - // Projet + // Projet if ($conf->projet->enabled) { $langs->load("projects"); - print ''; + print ''; print ''; + print ''; } print '
'.$langs->trans('Ref').''.$object->ref.'
'.$langs->trans("Company").''.$soc->getNomUrl(1,'compta').'
'.$langs->trans("Date").''.dol_print_date($object->date,"daytext").''.$langs->trans("DateMaxPayment").'' . dol_print_date($object->date_lim_reglement,"daytext"); - if ($object->paye == 0 && $object->date_lim_reglement < ($now - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); - print "
'.$langs->trans('Type').''; + print $object->getLibType(); + if ($object->type == 1) + { + $facreplaced=new Facture($db); + $facreplaced->fetch($object->fk_facture_source); + print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; + } + if ($object->type == 2) + { + $facusing=new Facture($db); + $facusing->fetch($object->fk_facture_source); + print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')'; + } - // Conditions et modes de reglement - print '
'.$langs->trans("PaymentConditions").''; - $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->cond_reglement_id,"none"); - print ''.$langs->trans("PaymentMode").''; - $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->mode_reglement_id,"none"); + $facidavoir=$object->getListIdAvoirFromInvoice(); + if (sizeof($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i=0; + foreach($facidavoir as $id) + { + if ($i==0) print ' '; + else print ','; + $facavoir=new Facture($db); + $facavoir->fetch($id); + print $facavoir->getNomUrl(1); + } + print ')'; + } + if ($objectidnext > 0) + { + $facthatreplace=new Facture($db); + $facthatreplace->fetch($objectidnext); + print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; + } print '
'.$langs->trans('GlobalDiscount').''.$object->remise_percent.'%
'.$langs->trans('Discounts'); + print ''; + if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + + if ($absolute_discount > 0) + { + print '. '; + if ($object->statut > 0 || $object->type == 2 || $object->type == 3) + { + if ($object->statut == 0) + { + print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); + print '. '; + } + else + { + if ($object->statut < 1 || $object->type == 2 || $object->type == 3) + { + $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); + print '
'.$text.'.
'; + } + else + { + $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); + $text2=$langs->trans("AbsoluteDiscountUse"); + print $html->textwithpicto($text,$text2); + } + } + } + else + { + // Remise dispo de type remise fixe (not credit note) + $filter='fk_facture_source IS NULL'; + print '
'; + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id',$soc->id, $absolute_discount, $filter, $resteapayer, ' - '.$addabsolutediscount); + } + } + else + { + if ($absolute_creditnote > 0) // If not linke will be added later + { + if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'
'; + else print '.'; + } + else print '. '; + } + if ($absolute_creditnote > 0) + { + // If validated, we show link "add credit note to payment" + if ($object->statut != 1 || $object->type == 2 || $object->type == 3) + { + if ($object->statut == 0 && $object->type != 3) + { + $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)); + print $html->textwithpicto($text,$langs->trans("CreditNoteDepositUse")); + } + else + { + print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.'; + } + } + else + { + // Remise dispo de type avoir + $filter='fk_facture_source IS NOT NULL'; + if (! $absolute_discount) print '
'; + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filter, $resteapayer); + } + } + if (! $absolute_discount && ! $absolute_creditnote) + { + print $langs->trans("CompanyHasNoAbsoluteDiscount"); + if ($object->statut == 0 && $object->type != 2 && $object->type != 3) print ' - '.$addabsolutediscount.'
'; + else print '. '; + } + /*if ($object->statut == 0 && $object->type != 2 && $object->type != 3) + { + if (! $absolute_discount && ! $absolute_creditnote) print '
'; + //print '   -   '; + print $addabsolutediscount; + //print '   -   '.$addcreditnote; // We disbale link to credit note + }*/ + print '
'.$langs->trans("Date").''.dol_print_date($object->date,"daytext").'
'; + print ''; + if ($object->type != 2 && $action != 'editpaymentterm' && $object->brouillon && $user->rights->facture->creer) print ''; + print '
'; + print $langs->trans('DateMaxPayment'); + print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; + print '
'; + if ($object->type != 2) + { + if ($action == 'editpaymentterm') + { + $html->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->date_lim_reglement,'paymentterm'); + } + else + { + print dol_print_date($object->date_lim_reglement,'daytext'); + if ($object->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $object->paye && $object->statut == 1 && ! $object->am) print img_warning($langs->trans('Late')); + } + } + else + { + print ' '; + } + print '
'.$langs->trans("PaymentConditionsShort").''; + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->cond_reglement_id,"none"); + print '
'; + print ''; + if ($action != 'editmode' && $object->brouillon && $user->rights->facture->creer) print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; + print '
'; + if ($action == 'editmode') + { + $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); + } + else + { + $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->mode_reglement_id,'none'); + } + print ''.price($object->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($object->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($object->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Status').''.($object->getLibStatut()).'
'.$langs->trans('Status').''.($object->getLibStatut(4,$totalpaye)).'
'.$langs->trans("Project").''; if ($object->fk_project > 0) { @@ -206,7 +372,7 @@ if ($id > 0 || ! empty($ref)) { print ' '; } - print '
'; @@ -223,22 +389,22 @@ if ($id > 0 || ! empty($ref)) // Si fichier png PDF d'1 page trouve if (file_exists($fileimage)) { - print ''; + print ''; } // Si fichier png PDF de plus d'1 page trouve elseif (file_exists($fileimagebis)) { - $multiple = preg_replace('/\.png/','',$relativepath) . "-"; + $multiple = preg_replace('/\.png/','',$relativepath) . "-"; - for ($i = 0; $i < 20; $i++) - { - $preview = $multiple.$i.'.png'; + for ($i = 0; $i < 20; $i++) + { + $preview = $multiple.$i.'.png'; - if (file_exists($dir_output.$preview)) - { - print '

'; - } - } + if (file_exists($dir_output.$preview)) + { + print '

'; + } + } } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4247c1f8eb2..781750c8d62 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2207,14 +2207,65 @@ class Facture extends CommonObject } else { - $this->error=$this->lasterror(); + $this->error=$this->db->lasterror(); return -1; } } /** - * \brief Return amount (with tax) of all credit notes and deposits invoices used by invoice - * \return int <0 if KO, Sum of credit notes and deposits amount otherwise + * Return list of payments + * @return Array with list of payments + */ + function getListOfPayments($filtertype='') + { + $retarray=array(); + + $table='paiement_facture'; + $table2='paiement'; + $field='fk_facture'; + $field2='fk_paiement'; + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') + { + $table='paiementfourn_facturefourn'; + $table2='paiementfourn'; + $field='fk_facturefourn'; + $field2='fk_paiementfourn'; + } + + $sql = 'SELECT pf.amount, p.fk_paiement, p.datep, t.code'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$table.' as pf, '.MAIN_DB_PREFIX.$table2.' as p, '.MAIN_DB_PREFIX.'c_paiement as t'; + $sql.= ' WHERE pf.'.$field.' = '.$this->id; + $sql.= ' AND pf.'.$field2.' = p.rowid'; + $sql.= ' AND p.fk_paiement = t.rowid'; + if ($filtertype) $sql.=" AND t.code='PRE'"; + + dol_syslog("Facture::getListOfPayments sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->code, 'date'=>$obj->datep); + $i++; + } + $this->db->free($resql); + return $retarray; + } + else + { + $this->error=$this->db->lasterror(); + dol_print_error($this->db); + return array(); + } + } + + + /** + * Return amount (with tax) of all credit notes and deposits invoices used by invoice + * @return int <0 if KO, Sum of credit notes and deposits amount otherwise */ function getSumCreditNotesUsed() { @@ -2234,8 +2285,8 @@ class Facture extends CommonObject } /** - * \brief Return amount (with tax) of all deposits invoices used by invoice - * \return int <0 if KO, Sum of deposits amount otherwise + * Return amount (with tax) of all deposits invoices used by invoice + * @return int <0 if KO, Sum of deposits amount otherwise */ function getSumDepositsUsed() { @@ -2902,9 +2953,9 @@ class Facture extends CommonObject } /** - * \brief Supprime une demande de prelevement - * \param user utilisateur creant la demande - * \param did id de la demande a supprimer + * Supprime une demande de prelevement + * @param user utilisateur creant la demande + * @param did id de la demande a supprimer */ function demande_prelevement_delete($user, $did) { diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 421fdfaab91..f3ec34fdd2a 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -400,6 +400,7 @@ if ($_REQUEST["facid"] > 0 || $_REQUEST["ref"]) dol_fiche_end(); + /* * Withdrawal request */ @@ -443,6 +444,9 @@ if ($_REQUEST["facid"] > 0 || $_REQUEST["ref"]) print "
\n"; + print $langs->trans("DoStandingOrdersBeforePayments").'
'; + + /* * Withdrawals */ diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index f602b5e0316..3e77bdfab70 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke @@ -246,7 +246,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid); $formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type); } - + // Invoice with Paypal transaction if ($conf->paypalplus->enabled && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && ! empty($facture->ref_int)) { @@ -285,7 +285,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''."\n"; } - print '

'; + print ''; print ''; print ''; print ''; @@ -634,6 +634,11 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie { // print ''; print '

'.$langs->trans("ClosePaidInvoicesAutomatically"); + /*if ($conf->prelevement->enabled) + { + $langs->load("withdrawals"); + if ($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS) print '
'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed"); + }*/ print '
'; // print ''; } diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 14e6f1829e7..2d54cc9458c 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -185,12 +185,25 @@ class Paiement extends CommonObject $deposits=$invoice->getSumDepositsUsed(); $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); - - if ($remaintopay == 0) + // If there is withdrawals request to do and not done yet, we wait before closing. + $mustwait=0; + $listofpayments=$invoice->getListOfPayments(); + foreach($listofpayments as $paym) { - $result=$invoice->set_paid($user,'',''); + // This payment might be this one or a previous one + if ($paym['type']=='PRE') + { + if ($conf->prelevement->enabled) + { + // TODO Check if this payment has a withdraw request + // if not, $mustwait++; // This will disable automatic close on invoice to allow to process + } + } } - else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing."); + + if ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more."); + else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more."); + else $result=$invoice->set_paid($user,'',''); } } else @@ -282,7 +295,7 @@ class Paiement extends CommonObject } } - // Efface la ligne de paiement (dans paiement_facture et paiement) + // Delete payment (into paiement_facture and paiement) $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture'; $sql.= ' WHERE fk_paiement = '.$this->id; $result = $this->db->query($sql); @@ -430,7 +443,7 @@ class Paiement extends CommonObject } } } - + if (! $error && ! $notrigger) { // Appel des triggers diff --git a/htdocs/compta/prelevement/class/bon-prelevement.class.php b/htdocs/compta/prelevement/class/bon-prelevement.class.php index c43586e7fa3..5b93052ec98 100644 --- a/htdocs/compta/prelevement/class/bon-prelevement.class.php +++ b/htdocs/compta/prelevement/class/bon-prelevement.class.php @@ -60,7 +60,7 @@ class BonPrelevement extends CommonObject function BonPrelevement($DB, $filename='') { global $conf,$langs; - + $error = 0; $this->db = $DB; @@ -84,8 +84,8 @@ class BonPrelevement extends CommonObject $this->methodes_trans[0] = "Internet"; $this->_fetched = 0; - - + + $langs->load("withdrawals"); $this->labelstatut[0]=$langs->trans("StatusWaiting"); $this->labelstatut[1]=$langs->trans("StatusTrans"); @@ -102,7 +102,7 @@ class BonPrelevement extends CommonObject * @param amount amount of invoice * @param code_banque code of bank withdrawal * @param code_guichet code of bank's office - * @param number bank account number + * @param number bank account number * @param number_key number key of account number * @return int >0 if OK, <0 if KO */ @@ -159,7 +159,7 @@ class BonPrelevement extends CommonObject * @param amount amount of invoice * @param code_banque code of bank withdrawal * @param code_guichet code of bank's office - * @param number bank account number + * @param number bank account number * @param number_key number key of account number * @return int >0 if OK, <0 if KO */ @@ -235,7 +235,7 @@ class BonPrelevement extends CommonObject /** * Read errors * @param error id of error - * @return array of errors + * @return array of errors */ function ReadError($error) { @@ -386,7 +386,7 @@ class BonPrelevement extends CommonObject /** * Set withdrawal to creditet status * @param user id of user - * @param date date of action + * @param date date of action * @return int >0 if OK, <0 if KO */ function set_infocredit($user, $date) @@ -411,18 +411,16 @@ class BonPrelevement extends CommonObject if ($this->db->query($sql)) { - + $langs->load('withdrawals'); - $subject = $langs->trans("InfoCreditSubject", $this->ref); + $subject = $langs->trans("InfoCreditSubject", $this->ref); $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date,'dayhour')); - - $this->Notify($user, "cr", $subject, $message); - + //Add payment of withdrawal into bank $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT; $facs = array(); $amounts = array(); - + $facs = $this->_get_list_factures(); for ($i = 0 ; $i < sizeof($facs) ; $i++) @@ -437,14 +435,14 @@ class BonPrelevement extends CommonObject $paiement->amounts = $amounts; $paiement->paiementid = 3; // $paiement->num_paiement = $this->ref ; - + $paiement_id = $paiement->create($user); if ($paiement_id < 0) { dol_syslog("BonPrelevement::set_credite AddPayment Error"); $error++; } - else + else { $result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount); if ($result < 0) @@ -453,7 +451,7 @@ class BonPrelevement extends CommonObject $error++; } } - // Update prelevement line + // Update prelevement line // TODO: Translate to ligne-prelevement.class.php $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; $sql.= " SET statut = 2"; @@ -464,7 +462,7 @@ class BonPrelevement extends CommonObject dol_syslog("BonPrelevement::set_credite Update lines Error"); $error++; } - + } else { @@ -509,7 +507,7 @@ class BonPrelevement extends CommonObject /** * Set withdrawal to transmited status * @param user id of user - * @param date date of action + * @param date date of action * @param method method of transmision to bank * @return int >0 if OK, <0 if KO */ @@ -534,11 +532,11 @@ class BonPrelevement extends CommonObject { $this->method_trans = $method; $langs->load('withdrawals'); - $subject = $langs->trans("InfoTransSubject", $this->ref); + $subject = $langs->trans("InfoTransSubject", $this->ref); $message = $langs->trans("InfoTransMessage", $this->ref, $user->prenom, $user->nom); $message .=$langs->trans("InfoTransData", price($this->amount), $this->methodes_trans[$this->method_trans], dol_print_date($date,'day')); - $this->Notify($user,"tr", $subject, $message, 1); + // TODO Call trigger to create a notification using notification module } else { @@ -551,7 +549,7 @@ class BonPrelevement extends CommonObject * End of procedure * */ - + if ($error == 0) { $this->db->commit(); @@ -574,67 +572,7 @@ class BonPrelevement extends CommonObject } /** - * Notify withdrawal actions - * @param user id of user - * @param action notify action - * @param subject message subject - * @param message message - * @param joinfile files joineds - * @return int >0 if OK, <0 if KO - */ - function Notify($user, $action, $subject, $message, $joinfile=0) - { - global $conf,$langs; - - $message .= "\n\n--\n"; - $message .= $langs->trans("InfoFoot"); //"Ceci est un message automatique envoye par Dolibarr"; - - $sql = "SELECT u.name, u.firstname, u.email"; - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql.= " , ".MAIN_DB_PREFIX."prelevement_notifications as pn"; - $sql.= " WHERE pn.action = '".$action."'"; - $sql.= " AND u.rowid = pn.fk_user"; - $sql.= " AND u.entity IN (0,".$conf->entity.")"; - dol_syslog("BonPrelevement::Notify: ".$sql, LOG_CRIT); - $resql = $this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - - require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); - - $sendto = $obj->firstname . " " .$obj->name . "<".$obj->email.">"; - $from = $user->prenom . " " .$user->nom . "<".$user->email.">"; - $arr_file = array(); - $arr_mime = array(); - $arr_name = array(); - $msgishtml=0; - - if ($joinfile == 1) - { - $arr_file = array($conf->prelevement->dir_output.'/receipts/'.$this->ref.'.ps'); - $arr_mime = array("application/ps"); - $arr_name = array($this->ref.".ps"); - } - - $mailfile = new CMailFile($subject,$sendto,$from,$message, - $arr_file,$arr_mime,$arr_name, - '', '', 0, $msgishtml); - - $result=$mailfile->sendfile(); - - $i++; - } - $this->db->free($resql); - } - } - - /** - * Get invoice list + * Get invoice list * @return array id of invoices */ function _get_list_factures() @@ -775,7 +713,7 @@ class BonPrelevement extends CommonObject require_once (DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once (DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); - + $error = 0; $datetimeprev = time(); @@ -986,17 +924,17 @@ class BonPrelevement extends CommonObject // Fetch invoice $fact = new Facture($this->db); $fact->fetch($fac[0]); - /* - * Add standing order - * - * - * $fac[3] : banque - * $fac[4] : guichet - * $fac[5] : number - * $fac[6] : cle rib - * $fac[7] : amount - * $fac[8] : client nom - * $fac[2] : client id + /* + * Add standing order + * + * + * $fac[3] : banque + * $fac[4] : guichet + * $fac[5] : number + * $fac[6] : cle rib + * $fac[7] : amount + * $fac[8] : client nom + * $fac[2] : client id */ $ri = $bonprev->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6]); @@ -1028,7 +966,7 @@ class BonPrelevement extends CommonObject } } - + } } @@ -1053,7 +991,7 @@ class BonPrelevement extends CommonObject $bonprev->emetteur_code_guichet = $conf->global->PRELEVEMENT_CODE_GUICHET; $bonprev->emetteur_numero_compte = $conf->global->PRELEVEMENT_NUMERO_COMPTE; $bonprev->emetteur_number_key = $conf->global->PRELEVEMENT_NUMBER_KEY; - + $bonprev->factures = $factures_prev_id; //Build file @@ -1190,7 +1128,7 @@ class BonPrelevement extends CommonObject { $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)"; $sql .= " VALUES (".$db->idate(mktime()).",".$user.", 'NULL', 'NULL', ".$action.")"; - + dol_syslog("adnotiff: ".$sql); if ($this->db->query($sql)) { @@ -1230,7 +1168,7 @@ class BonPrelevement extends CommonObject //Build file for Spain if ($mysoc->pays_code=='ES') { - if ($conf->esaeb->enabled) + if ($conf->esaeb->enabled) { //Head $esaeb19 = new AEB19DocWritter; @@ -1246,18 +1184,18 @@ class BonPrelevement extends CommonObject $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; $sql.= " AND pf.fk_facture = f.rowid"; - + //Lines $i = 0; $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ($i < $num) { $obj = $this->db->fetch_object($resql); - + $esaeb19->agregaRecibo($idOrdenante, "idcliente".$i+1, $obj->client_nom, @@ -1267,21 +1205,21 @@ class BonPrelevement extends CommonObject $obj->number, $obj->amount, "Fra.".$obj->facnumber." ".$obj->amount); - + $this->total = $this->total + $obj->amount; - + $i++; } } - + else { $result = -2; } - + fputs ($this->file, $esaeb19->generaRemesa()); } - else + else { $this->total = 0; $sql = "SELECT pl.amount"; @@ -1292,14 +1230,14 @@ class BonPrelevement extends CommonObject $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; $sql.= " AND pf.fk_facture = f.rowid"; - + //Lines $i = 0; $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ($i < $num) { $obj = $this->db->fetch_object($resql); @@ -1314,9 +1252,9 @@ class BonPrelevement extends CommonObject $langs->load('withdrawals'); fputs ($this->file, $langs->trans('WithdrawalFileNotCapable')); } - + } - + //Build file for France elseif ($mysoc->pays_code=='FR') { @@ -1376,9 +1314,9 @@ class BonPrelevement extends CommonObject $this->EnregTotal($this->total); } - - //Build file for Other Countries with unknow format - else + + //Build file for Other Countries with unknow format + else { $this->total = 0; $sql = "SELECT pl.amount"; @@ -1389,14 +1327,14 @@ class BonPrelevement extends CommonObject $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; $sql.= " AND pf.fk_facture = f.rowid"; - + //Lines $i = 0; $resql=$this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ($i < $num) { $obj = $this->db->fetch_object($resql); @@ -1416,7 +1354,7 @@ class BonPrelevement extends CommonObject if (! empty($conf->global->MAIN_UMASK)) @chmod($this->file, octdec($conf->global->MAIN_UMASK)); return $result; - + } @@ -1611,7 +1549,7 @@ class BonPrelevement extends CommonObject fputs ($this->file, "\n"); } - + /** * Return status label of object * @param mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto @@ -1636,7 +1574,7 @@ class BonPrelevement extends CommonObject { return $langs->trans($this->labelstatut[$statut]); } - + if ($mode == 1) { if ($statut==0) return img_picto($langs->trans($this->labelstatut[$statut]),'statut0').' '.$langs->trans($this->labelstatut[$statut]); @@ -1649,7 +1587,7 @@ class BonPrelevement extends CommonObject if ($statut==1) return img_picto($langs->trans($this->labelstatut[$statut]),'statut1'); if ($statut==2) return img_picto($langs->trans($this->labelstatut[$statut]),'statut4'); } - + if ($mode == 3) { if ($statut==0) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut0'); @@ -1657,7 +1595,7 @@ class BonPrelevement extends CommonObject if ($statut==2) return $langs->trans($this->labelstatut[$statut]).' '.img_picto($langs->trans($this->labelstatut[$statut]),'statut4'); } } - + } ?> \ No newline at end of file diff --git a/htdocs/compta/prelevement/index.php b/htdocs/compta/prelevement/index.php index 65924c271d2..a124e5832c9 100644 --- a/htdocs/compta/prelevement/index.php +++ b/htdocs/compta/prelevement/index.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2010 Laurent Destailleur + * Copyright (C) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2011 Juanjo Menent * @@ -76,7 +76,9 @@ print ''.$langs->trans("Statistics").''.$langs->trans("NbOfInvoiceToWithdraw").''; print ''; +print ''; print $bprev->NbFactureAPrelever(); +print ''; print ''; $var=!$var; print ''.$langs->trans("AmountToWithdraw").''; @@ -86,6 +88,57 @@ print '
'; print ''; + + +/* + * Withdraw receipts + */ +$limit=5; +$sql = "SELECT p.rowid, p.ref, p.amount, p.datec"; +$sql .= " ,p.statut "; +$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; +$sql .= " ORDER BY datec DESC LIMIT ".$limit; + +$result = $db->query($sql); +if ($result) +{ + $num = $db->num_rows($result); + $i = 0; + $var=True; + + print"\n\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + + while ($i < min($num,$limit)) + { + $obj = $db->fetch_object($result); + $var=!$var; + + print "\n"; + + print '\n"; + + print '\n"; + + print "\n"; + $i++; + } + print "
'.$langs->trans("LastWithdrawalReceipt",$limit).''.$langs->trans("Date").''.$langs->trans("Amount").'
"; + + print ' '; + + print ''.$obj->ref."'.dol_print_date($db->jdate($obj->datec),"dayhour")."'.price($obj->amount)."

"; + $db->free($result); +} +else +{ + dol_print_error($db); +} + /* * Invoices waiting for withdraw */ @@ -163,56 +216,6 @@ else } - -/* - * Withdraw receipts - */ -$limit=5; -$sql = "SELECT p.rowid, p.ref, p.amount, p.datec"; -$sql .= " ,p.statut "; -$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p"; -$sql .= " ORDER BY datec DESC LIMIT ".$limit; - -$result = $db->query($sql); -if ($result) -{ - $num = $db->num_rows($result); - $i = 0; - $var=True; - - print"\n\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - - while ($i < min($num,$limit)) - { - $obj = $db->fetch_object($result); - $var=!$var; - - print "\n"; - - print '\n"; - - print '\n"; - - print "\n"; - $i++; - } - print "
'.$langs->trans("LastWithdrawalReceipt",$limit).''.$langs->trans("Date").''.$langs->trans("Amount").'
"; - - print ' '; - - print ''.$obj->ref."'.dol_print_date($db->jdate($obj->datec),"dayhour")."'.price($obj->amount)."
"; - $db->free($result); -} -else -{ - dol_print_error($db); -} - print ''; llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/compta/prelevement/stats.php b/htdocs/compta/prelevement/stats.php index 6320b003bf8..7fffba4386b 100644 --- a/htdocs/compta/prelevement/stats.php +++ b/htdocs/compta/prelevement/stats.php @@ -44,7 +44,7 @@ $result = restrictedArea($user, 'prelevement','','','bons'); llxHeader('',$langs->trans("WithdrawStatistics")); -print_fiche_titre($langs->trans("WithdrawStatistics")); +print_fiche_titre($langs->trans("Statistics")); // Define total and nbtotal $sql = "SELECT sum(pl.amount), count(pl.amount)"; @@ -70,6 +70,10 @@ if ($resql) /* * Stats */ + +print '
'; +print_titre($langs->trans("WithdrawStatistics")); + $ligne=new LignePrelevement($db,$user); $sql = "SELECT sum(pl.amount), count(pl.amount), pl.statut"; @@ -140,6 +144,7 @@ else print '
'; print_titre($langs->trans("WithdrawRejectStatistics")); + // Define total and nbtotal $sql = "SELECT sum(pl.amount), count(pl.amount)"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; diff --git a/htdocs/includes/menus/init_menu_auguria.sql b/htdocs/includes/menus/init_menu_auguria.sql index c572ecf184c..c8f7c9a148a 100644 --- a/htdocs/includes/menus/init_menu_auguria.sql +++ b/htdocs/includes/menus/init_menu_auguria.sql @@ -207,7 +207,6 @@ insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk -- Withdrawal insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('$conf->prelevement->enabled', __HANDLER__, 'left', 2500__+MAX_llx_menu__, 'accountancy', '', 14__+MAX_llx_menu__, '/compta/prelevement/index.php?leftmenu=withdraw&mainmenu=bank', 'StandingOrders', 0, 'withdrawals', '$user->rights->prelevement->bons->lire', '', 2, 9, __ENTITY__); insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('$conf->prelevement->enabled && $leftmenu=="withdraw"', __HANDLER__, 'left', 2502__+MAX_llx_menu__, 'accountancy', '', 2500__+MAX_llx_menu__, '/compta/prelevement/create.php?leftmenu=withdraw', 'NewStandingOrder', 1, 'withdrawals', '$user->rights->prelevement->bons->lire', '', 2, 0, __ENTITY__); -insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('$conf->prelevement->enabled && $leftmenu=="withdraw"', __HANDLER__, 'left', 2501__+MAX_llx_menu__, 'accountancy', '', 2500__+MAX_llx_menu__, '/compta/prelevement/demandes.php?status=0&leftmenu=withdraw', 'StandingOrderToProcess', 1, 'withdrawals', '$user->rights->prelevement->bons->lire', '', 2, 1, __ENTITY__); insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('$conf->prelevement->enabled && $leftmenu=="withdraw"', __HANDLER__, 'left', 2503__+MAX_llx_menu__, 'accountancy', '', 2500__+MAX_llx_menu__, '/compta/prelevement/bons.php?leftmenu=withdraw', 'WithdrawalsReceipts', 1, 'withdrawals', '$user->rights->prelevement->bons->lire', '', 2, 2, __ENTITY__); insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('$conf->prelevement->enabled && $leftmenu=="withdraw"', __HANDLER__, 'left', 2504__+MAX_llx_menu__, 'accountancy', '', 2500__+MAX_llx_menu__, '/compta/prelevement/liste.php?leftmenu=withdraw', 'WithdrawalsLines', 1, 'withdrawals', '$user->rights->prelevement->bons->lire', '', 2, 3, __ENTITY__); insert into llx_menu (enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('$conf->prelevement->enabled && $leftmenu=="withdraw"', __HANDLER__, 'left', 2506__+MAX_llx_menu__, 'accountancy', '', 2500__+MAX_llx_menu__, '/compta/prelevement/rejets.php?leftmenu=withdraw', 'Rejects', 1, 'withdrawals', '$user->rights->prelevement->bons->lire', '', 2, 5, __ENTITY__); diff --git a/htdocs/includes/menus/standard/eldy.lib.php b/htdocs/includes/menus/standard/eldy.lib.php index cbd7681633e..cb7b87de370 100644 --- a/htdocs/includes/menus/standard/eldy.lib.php +++ b/htdocs/includes/menus/standard/eldy.lib.php @@ -1025,11 +1025,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after) { $newmenu->add("/compta/prelevement/index.php?leftmenu=withdraw&mainmenu=bank",$langs->trans("StandingOrders"),0,$user->rights->prelevement->bons->lire); + //if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/demandes.php?status=0&mainmenu=bank",$langs->trans("StandingOrderToProcess"),1,$user->rights->prelevement->bons->lire); + if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/create.php?mainmenu=bank",$langs->trans("NewStandingOrder"),1,$user->rights->prelevement->bons->creer); - //if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/demandes.php",$langs->trans("StandingOrder"),1,$user->rights->prelevement->bons->lire); - if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/demandes.php?status=0&mainmenu=bank",$langs->trans("StandingOrderToProcess"),1,$user->rights->prelevement->bons->lire); - //if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/demandes.php?status=1",$langs->trans("StandingOrderProcessed"),2,$user->rights->prelevement->bons->lire); if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/bons.php?mainmenu=bank",$langs->trans("WithdrawalsReceipts"),1,$user->rights->prelevement->bons->lire); if ($leftmenu=="withdraw") $newmenu->add("/compta/prelevement/liste.php?mainmenu=bank",$langs->trans("WithdrawalsLines"),1,$user->rights->prelevement->bons->lire); diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index 23fa75e94f7..e67cf10f7b6 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -10,6 +10,8 @@ -- To change type of field: ALTER TABLE llx_table MODIFY name varchar(60); -- +DROP table llx_prelevement_notifications; + -- Fix corrupted data update llx_deplacement set dated='2010-01-01' where dated < '2000-01-01'; @@ -376,3 +378,4 @@ update llx_actioncomm set elementtype='contract' where elementtype='contrat'; alter table llx_propal add column tms timestamp after fk_projet; + diff --git a/htdocs/install/mysql/tables/llx_prelevement_notifications.sql b/htdocs/install/mysql/tables/llx_prelevement_notifications.sql deleted file mode 100644 index 79fef1724e2..00000000000 --- a/htdocs/install/mysql/tables/llx_prelevement_notifications.sql +++ /dev/null @@ -1,36 +0,0 @@ --- =================================================================== --- Copyright (C) 2005 Rodolphe Quiedeville --- Copyright (C) 2010 Juanjo Menent --- --- 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. --- --- $Id$ --- =================================================================== - --- --- Utilisateur a notifier --- --- actions : --- 'NOTIFY_EMT_WITHDRAW' emission d'un bon --- 'NOTIFY_TRN_WITHDRAW' tranmission d'un bon --- 'NOTIFY_CRD_WITHDRAW' credit du bon par la banque - -create table llx_prelevement_notifications -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_user integer NOT NULL, - action varchar(32) - -)ENGINE=innodb; diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index 460d926d6c3..5488f674620 100755 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -79,6 +79,8 @@ BankToReceiveWithdraw=Bank account to receive withdraws CreditDate=Credit on WithdrawalFileNotCapable=Unable to generate withdrawal receipt file for your country ShowWithdraw=Show Withdraw +IfInvoiceNeedOnWithdrawPaymentWontBeClosed=However, if invoice has at least one withdrawal payment not yet processed, it won't be set as payed to allow to manage withdrawal before. +DoStandingOrdersBeforePayments=This tabs allows you to request for a standing order. Once it will be finished, you can type the payment to close the invoice. ### Notifications InfoCreditSubject=Payment of standing order %s by the bank diff --git a/htdocs/langs/fr_FR/withdrawals.lang b/htdocs/langs/fr_FR/withdrawals.lang index cb84d818ae3..a346376dd42 100755 --- a/htdocs/langs/fr_FR/withdrawals.lang +++ b/htdocs/langs/fr_FR/withdrawals.lang @@ -79,6 +79,8 @@ BankToReceiveWithdraw=Compte bancaire recevant les prélèvements CreditDate=Crédité le WithdrawalFileNotCapable=Impossible de generer fichier de bon de prelevements pour votre pays ShowWithdraw=Voir prélèvement +IfInvoiceNeedOnWithdrawPaymentWontBeClosed=Toutefois, si la facture a au moins un paiement par prélèvement non traité, elle ne le sera pas afin de permettre la gestion du prélèvement d'abord. +DoStandingOrdersBeforePayments=Cet onglet permet de faire une demande de pélèvement bancaire. Une fois terminé, vous pourrez saisir le payement sur la facture pour la clore. ### Notifications InfoCreditSubject=Credit prélèvement %s a la banque diff --git a/htdocs/lib/prelevement.lib.php b/htdocs/lib/prelevement.lib.php index f5d57d2817c..a6879b8f0b1 100644 --- a/htdocs/lib/prelevement.lib.php +++ b/htdocs/lib/prelevement.lib.php @@ -86,18 +86,15 @@ function prelevement_prepare_head($object) /** * Check need data to create standigns orders receipt file - * @return int -1 if ko 0 if ok + * @return int -1 if ko 0 if ok */ function prelevement_check_config() { global $conf; - if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1; - if(empty($conf->global->PRELEVEMENT_CODE_BANQUE)) return -1; - if(empty($conf->global->PRELEVEMENT_CODE_GUICHET)) return -1; - if(empty($conf->global->PRELEVEMENT_NUMERO_COMPTE)) return -1; - if(empty($conf->global->PRELEVEMENT_NUMBER_KEY)) return -1; - if(empty($conf->global->PRELEVEMENT_RAISON_SOCIALE)) return -1; + if(empty($conf->global->PRELEVEMENT_USER)) return -1; + if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1; if(empty($conf->global->PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR)) return -1; - return 0; + return 0; } + ?> \ No newline at end of file