diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index 7dffc753bc4eaae78f32503be3b27d4f807109f8..f2a7649166a2b2b40c42e6d10ec14d7ba9421d36 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -39,6 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -50,6 +51,7 @@ $langs->load("companies"); $langs->load("salaries"); $langs->load("loan"); $langs->load("donations"); +$langs->load("trips"); $id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int')); $ref = GETPOST('ref','alpha'); @@ -188,6 +190,7 @@ $paymentsupplierstatic=new PaiementFourn($db); $paymentvatstatic=new TVA($db); $paymentsalstatic=new PaymentSalary($db); $donstatic=new Don($db); +$expensereportstatic=new ExpenseReport($db); $bankstatic=new Account($db); $banklinestatic=new AccountLine($db); @@ -732,6 +735,12 @@ if ($id > 0 || ! empty($ref)) print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; print '</a>'; } + elseif ($links[$key]['type']=='payment_expensereport') + { + print '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$links[$key]['url_id'].'">'; + print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; + print '</a>'; + } elseif ($links[$key]['type']=='banktransfert') { // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. diff --git a/htdocs/don/class/paymentdonation.class.php b/htdocs/don/class/paymentdonation.class.php index 2d75cd392fc0dbe68fd2bfba823b7d1f99fb28b8..27784446e4bc01ac153d87050900a5c8b691eeb9 100644 --- a/htdocs/don/class/paymentdonation.class.php +++ b/htdocs/don/class/paymentdonation.class.php @@ -42,7 +42,7 @@ class PaymentDonation extends CommonObject var $datep=''; var $amount; // Total amount of payment var $amounts=array(); // Array of amounts - var $fk_typepayment; + var $typepayment; var $num_payment; var $note; var $fk_bank; @@ -90,7 +90,7 @@ class PaymentDonation extends CommonObject // Clean parameters if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation); if (isset($this->amount)) $this->amount=trim($this->amount); - if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->typepayment)) $this->typepayment=trim($this->typepayment); if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); if (isset($this->note)) $this->note=trim($this->note); if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 0ab3ac799c9e734d8739144c77cb06c85626e55b..1a52f0dc19400d9fee9f2d21be598733ac3a91b8 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -36,9 +36,11 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; +require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; $langs->load("trips"); +$langs->load("bills"); $langs->load("mails"); $action=GETPOST('action'); @@ -825,6 +827,18 @@ if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && } } +if ($action == 'set_paid') +{ + if ($object->set_paid($id) >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + else { + setEventMessage($object->error, 'errors'); + } +} + if ($action == "addline") { $error = 0; @@ -1387,18 +1401,18 @@ else if ($ret == 'html') print '<br>'; } - print '<table class="border centpercent">'; + print '<table class="border" width="100%">'; $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>'; // Ref - print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>'; + print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="2">'; print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); print '</td></tr>'; print '<tr>'; print '<td>'.$langs->trans("Period").'</td>'; - print '<td>'; + print '<td colspan="2">'; print get_date_range($object->date_debut,$object->date_fin,'',$langs,0); print '</td>'; print '</tr>'; @@ -1406,25 +1420,90 @@ else { print '<tr>'; print '<td>'.$langs->trans("ModePaiement").'</td>'; - print '<td>'.$object->libelle_paiement.'</td>'; + print '<td colspan="2">'.$object->libelle_paiement.'</td>'; print '</tr>'; } // Status print '<tr>'; print '<td>'.$langs->trans("Statut").'</td>'; - print '<td>'.$object->getLibStatut(4).'</td>'; + print '<td colspan="2">'.$object->getLibStatut(4).'</td>'; print '</tr>'; print '<tr>'; print '<td>'.$langs->trans("NotePublic").'</td>'; - print '<td>'.$object->note_public.'</td>'; + print '<td colspan="2">'.$object->note_public.'</td>'; print '</tr>'; print '<tr>'; print '<td>'.$langs->trans("NotePrivate").'</td>'; - print '<td>'.$object->note_private.'</td>'; + print '<td colspan="2">'.$object->note_private.'</td>'; print '</tr>'; print '<tr>'; print '<td>'.$langs->trans("AmountHT").'</td>'; print '<td>'.price($object->total_ht).'</td>'; + print '<td rowspan="7" valign="top">'; + /* + * Payments + */ + $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,"; + $sql.= "c.code as type_code,c.libelle as payment_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p"; + $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; + $sql.= ", ".MAIN_DB_PREFIX."expensereport as e"; + $sql.= " WHERE e.rowid = '".$id."'"; + $sql.= " AND p.fk_expensereport = e.rowid"; + $sql.= " AND e.entity = ".$conf->entity; + $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " ORDER BY dp"; + + //print $sql; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; $total = 0; + print '<table class="nobordernopadding" width="100%">'; + print '<tr class="liste_titre">'; + print '<td>'.$langs->trans("RefPayment").'</td>'; + print '<td>'.$langs->trans("Date").'</td>'; + print '<td>'.$langs->trans("Type").'</td>'; + print '<td align="right">'.$langs->trans("Amount").'</td>'; + print '<td> </td>'; + print '</tr>'; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print "<tr ".$bc[$var]."><td>"; + print '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>'; + print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n"; + $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->fk_typepayment; + print "<td>".$labeltype.' '.$object->num_payment."</td>\n"; + print '<td align="right">'.price($objp->amount)."</td><td> ".$langs->trans("Currency".$conf->currency)."</td>\n"; + print "</tr>"; + $totalpaid += $objp->amount; + $i++; + } + + if ($object->paid == 0) + { + print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPaid")." :</td><td align=\"right\"><b>".price($totalpaid)."</b></td><td> ".$langs->trans("Currency".$conf->currency)."</td></tr>\n"; + print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AmountExpected")." :</td><td align=\"right\" bgcolor=\"#d0d0d0\">".price($object->total_ttc)."</td><td bgcolor=\"#d0d0d0\"> ".$langs->trans("Currency".$conf->currency)."</td></tr>\n"; + + $remaintopay = $object->total_ttc - $totalpaid; + + print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>"; + print "<td align=\"right\" bgcolor=\"#f0f0f0\"><b>".price($remaintopay)."</b></td><td bgcolor=\"#f0f0f0\"> ".$langs->trans("Currency".$conf->currency)."</td></tr>\n"; + } + print "</table>"; + $db->free($resql); + } + else + { + dol_print_error($db); + } + print "</td>"; + print '</tr>'; print '<tr>'; print '<td>'.$langs->trans("AmountVAT").'</td>'; @@ -1644,7 +1723,7 @@ else { //modif ligne!!!!! print '<tr '.$bc[$var].'>'; - // Sélection date + // Select date print '<td style="text-align:center;">'; $form->select_date($objp->date,'date'); print '</td>'; @@ -1797,8 +1876,6 @@ else } - - /* * Barre d'actions */ @@ -1873,9 +1950,9 @@ if ($action != 'create' && $action != 'edit') /* Si l'état est "En attente d'approbation" * ET user à droit de "approve" - * ET fk_user_validator == user courant - * Afficher : "Valider" / "Refuser" / "Supprimer" - */ + * ET fk_user_validator == user courant + * Afficher : "Valider" / "Refuser" / "Supprimer" + */ if ($object->fk_statut == 2) { if ($object->fk_user_author == $user->id) @@ -1907,34 +1984,46 @@ if ($action != 'create' && $action != 'edit') print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a>'; } } - + /* Si l'état est "A payer" * ET user à droit de "to_paid" - * Afficher : "Annuler" / "Payer" / "Supprimer" - */ + * Afficher : "Annuler" / "Payer" / "Supprimer" + */ if ($user->rights->expensereport->to_paid && $object->fk_statut == 5) { // Pay - print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=paid&id='.$object->id.'">'.$langs->trans('TO_PAID').'</a>'; + if ($remaintopay == 0) + { + print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>'; + } + else + { + print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/payment/payment.php?id=' . $object->id . '&action=create">' . $langs->trans('DoPayment') . '</a></div>'; + } + + if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer) + { + print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>"; + } // Cancel if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a>'; } - + + // Delete if($user->rights->expensereport->supprimer) { - // Delete print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a>'; } } /* Si l'état est "Payée" * ET user à droit "approve" - * ET user à droit "to_paid" - * Afficher : "Annuler" - */ + * ET user à droit "to_paid" + * Afficher : "Annuler" + */ if ($user->rights->expensereport->approve && $user->rights->expensereport->to_paid && $object->fk_statut==6) { // Cancel diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 98a6aea00e7ebc268e59ecbc8764d73a8cbf9a0f..914ff34043dafc45fc49a198135bf22618e2fcce 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -50,12 +50,13 @@ class ExpenseReport extends CommonObject var $status; var $fk_statut; // -- 1=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied var $fk_c_paiement; + var $paid; var $user_author_infos; var $user_validator_infos; - var $libelle_paiement; - var $libelle_statut; + var $modepayment; + var $modepaymentid; var $code_paiement; var $code_statut; @@ -107,6 +108,7 @@ class ExpenseReport extends CommonObject $this->total_ht = 0; $this->total_ttc = 0; $this->total_tva = 0; + $this->modepaymentid = 0; // List of language codes for status $this->statuts_short = array(0 => 'Draft', 2 => 'Validated', 4 => 'Canceled', 5 => 'Approved', 6 => 'Paid', 99 => 'Refused'); @@ -142,6 +144,7 @@ class ExpenseReport extends CommonObject $sql.= ",fk_user_validator"; $sql.= ",fk_statut"; $sql.= ",fk_c_paiement"; + $sql.= ",paid"; $sql.= ",note_public"; $sql.= ",note_private"; $sql.= ") VALUES("; @@ -155,7 +158,8 @@ class ExpenseReport extends CommonObject $sql.= ", ".($user->id > 0 ? $user->id:"null"); $sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); $sql.= ", ".($this->fk_statut > 1 ? $this->fk_statut:0); - $sql.= ", ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null"); + $sql.= ", ".($this->modepaymentid?$this->modepaymentid:"null"); + $sql.= ", 0"; $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); $sql.= ")"; @@ -325,9 +329,10 @@ class ExpenseReport extends CommonObject if ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator); $this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname); - $this->fk_statut = $obj->status; - $this->status = $obj->status; - $this->fk_c_paiement = $obj->fk_c_paiement; + $this->fk_statut = $obj->status; + $this->status = $obj->status; + $this->fk_c_paiement = $obj->fk_c_paiement; + $this->paid = $obj->paid; if ($this->fk_statut==5 || $this->fk_statut==6) { @@ -367,6 +372,35 @@ class ExpenseReport extends CommonObject } } + /** + * Classify the expense report as paid + * + * @param int $id id of expense report + * @return int <0 if KO, >0 if OK + */ + function set_paid($id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport SET fk_statut = 6"; + $sql.= " WHERE rowid = $id AND fk_statut = 5"; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->affected_rows($resql)) + { + return 1; + } + else + { + return 0; + } + } + else + { + dol_print_error($this->db); + return -1; + } + } /** * Returns the label status diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php new file mode 100644 index 0000000000000000000000000000000000000000..0c46943de4993dfdb797e4068ebbca318d082215 --- /dev/null +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -0,0 +1,592 @@ +<?php +/* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file htdocs/expensereport/class/paymentexpensereport.class.php + * \ingroup Expense Report + * \brief File of class to manage payment of expense report + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** \class PaymentExpenseReport + * \brief Class to manage payments of expense report + */ +class PaymentExpenseReport extends CommonObject +{ + public $element='payment_expensereport'; //!< Id that identify managed objects + public $table_element='payment_expensereport'; //!< Name of table without prefix where object is stored + + var $id; + var $rowid; + var $ref; + + var $fk_expensereport; + var $datec=''; + var $tms=''; + var $datep=''; + var $amount; // Total amount of payment + var $amounts=array(); // Array of amounts + var $fk_typepayment; + var $num_payment; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + } + + /** + * Create payment of expense report into database. + * Use this->amounts to have list of lines for the payment + * + * @param User $user User making payment + * @return int <0 if KO, id of payment if OK + */ + function create($user) + { + global $conf, $langs; + + $error=0; + + $now=dol_now(); + + // Validate parameters + if (! $this->datepaid) + { + $this->error='ErrorBadValueForParameterCreatePaymentExpenseReport'; + return -1; + } + + // Clean parameters + if (isset($this->fk_expensereport)) $this->fk_expensereport=trim($this->fk_expensereport); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); + 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); + + $totalamount = 0; + foreach ($this->amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value,'MT'); + $this->amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + + + $this->db->begin(); + + if ($totalamount != 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_expensereport (fk_expensereport, datec, datep, amount,"; + $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; + $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; + $sql.= " '".$this->db->idate($this->datepaid)."',"; + $sql.= " ".$totalamount.","; + $sql.= " ".$this->fk_typepayment.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; + $sql.= " 0)"; + + 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."payment_expensereport"); + } + else + { + $error++; + } + + } + + if ($totalamount != 0 && ! $error) + { + $this->amount=$totalamount; + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + /** + * Load object in memory from database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.fk_expensereport,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount,"; + $sql.= " t.fk_typepayment,"; + $sql.= " t.num_payment,"; + $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."payment_expensereport 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_typepayment = pt.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->fk_expensereport = $obj->fk_expensereport; + $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_typepayment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; + $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(); + return -1; + } + } + + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function update($user=null, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_expensereport)) $this->fk_expensereport=trim($this->fk_expensereport); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); + 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."payment_expensereport SET"; + + $sql.= " fk_expensereport=".(isset($this->fk_expensereport)?$this->fk_expensereport:"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_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; + $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; + $sql.= " note=".(isset($this->note)?"'".$this->db->escape($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", 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; + } + } + + + /** + * Delete object in database + * + * @param User $user User that delete + * @param int $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_expensereport' AND url_id=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_expensereport"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", 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_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; + } + } + + + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; + + $error=0; + + $object=new PaymentExpenseReport($this->db); + + $object->context['createfromclone'] = 'createfromclone'; + + $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) + { + + + + } + + unset($this->context['createfromclone']); + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_expensereport=''; + $this->datec=''; + $this->tms=''; + $this->datep=''; + $this->amount=''; + $this->fk_typepayment=''; + $this->num_payment=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + + + } + + + /** + * Add 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 $user Object of user making payment + * @param string $mode 'payment_expensereport' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $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 (! empty($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_expensereport') $amount=$total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline( + $this->datepaid, + $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example") + $label, + $amount, + $this->num_payment, + '', + $user, + $emetteur_nom, + $emetteur_banque + ); + + // Update fk_bank in 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_expensereport' in bank_url between payment and bank transaction + $url=''; + if ($mode == 'payment_expensereport') $url=DOL_URL_ROOT.'/expensereport/payment/card.php?rowid='; + if ($url) + { + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + } + else + { + $this->error=$acc->error; + $error++; + } + } + + if (! $error) + { + return 1; + } + else + { + return -1; + } + } + + + /** + * Update link between the expense report payment and the generated line in llx_bank + * + * @param int $id_bank Id if bank + * @return int >0 if OK, <=0 if KO + */ + function update_fk_bank($id_bank) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_expensereport SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + $this->error=$this->db->error(); + return 0; + } + } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $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; + $label = $langs->trans("ShowPayment").': '.$this->ref; + + if (!empty($this->id)) + { + $link = '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; + $linkend='</a>'; + + if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; + } + + return $result; + } +} diff --git a/htdocs/expensereport/payment/card.php b/htdocs/expensereport/payment/card.php new file mode 100644 index 0000000000000000000000000000000000000000..5b62b13835610f5747d183f0e1755feb7c544767 --- /dev/null +++ b/htdocs/expensereport/payment/card.php @@ -0,0 +1,303 @@ +<?php +/* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file htdocs/expensereport/payment/card.php + * \ingroup Expense Report + * \brief Tab payment of an expense report + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load('bills'); +$langs->load('banks'); +$langs->load('companies'); + +// Security check +$id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int'); +$action=GETPOST("action"); +$confirm=GETPOST('confirm'); +if ($user->societe_id) $socid=$user->societe_id; +// TODO Add rule to restrict access payment +//$result = restrictedArea($user, 'facture', $id,''); + +$payment = new PaymentExpenseReport($db); +if ($id > 0) +{ + $result=$payment->fetch($id); + if (! $result) dol_print_error($db,'Failed to get payment id '.$id); +} + + +/* + * Actions + */ + +// Delete payment +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) +{ + $db->begin(); + + $result = $payment->delete($user); + if ($result > 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT."/expensereport/index.php"); + exit; + } + else + { + setEventMessage($payment->error, 'errors'); + $db->rollback(); + } +} + +// Create payment +if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensereport->creer) +{ + $db->begin(); + + $result=$payment->valide(); + + if ($result > 0) + { + $db->commit(); + + $factures=array(); // TODO Get all id of invoices linked to this payment + foreach($factures as $id) + { + $fac = new Facture($db); + $fac->fetch($id); + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $fac->generateDocument($fac->modelpdf, $outputlangs); + } + } + + header('Location: card.php?id='.$payment->id); + exit; + } + else + { + setEventMessage($payment->error); + $db->rollback(); + } +} + + +/* + * View + */ + +llxHeader(); + +$expensereport = new ExpenseReport($db); +$form = new Form($db); + +$h=0; + +$head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$id; +$head[$h][1] = $langs->trans("Card"); +$hselected = $h; +$h++; + +dol_fiche_head($head, $hselected, $langs->trans("ExpenseReportPayment"), 0, 'payment'); + +/* + * Confirm deleting of the payment + */ +if ($action == 'delete') +{ + print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + +} + +/* + * Confirm validation of the payment + */ +if ($action == 'valide') +{ + $facid = $_GET['facid']; + print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + +} + + +print '<table class="border" width="100%">'; + +// Ref +print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td>'; +print '<td colspan="3">'; +print $form->showrefnav($payment,'id','',1,'rowid','id'); +print '</td></tr>'; + +// Date +print '<tr><td valign="top">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($payment->datep,'day').'</td></tr>'; + +// Mode +print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>'; + +// Number +print '<tr><td valign="top">'.$langs->trans('Number').'</td><td colspan="3">'.$payment->num_payment.'</td></tr>'; + +// Amount +print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>'; + +// Note +print '<tr><td valign="top">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($payment->note).'</td></tr>'; + +// Bank account +if (! empty($conf->banque->enabled)) +{ + if ($payment->bank_account) + { + $bankline=new AccountLine($db); + $bankline->fetch($payment->bank_line); + + print '<tr>'; + print '<td>'.$langs->trans('BankTransactionLine').'</td>'; + print '<td colspan="3">'; + print $bankline->getNomUrl(1,0,'showall'); + print '</td>'; + print '</tr>'; + } +} + +print '</table>'; + + +/* + * List of donations paid + */ + +$disable_delete = 0; +$sql = 'SELECT er.rowid as did, er.paid, er.total_ttc, per.amount'; +$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er'; +$sql.= ' WHERE per.fk_expensereport = er.rowid'; +$sql.= ' AND er.entity = '.$conf->entity; +$sql.= ' AND per.rowid = '.$id; + +dol_syslog("expensereport/payment/card.php", LOG_DEBUG); +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + + $i = 0; + $total = 0; + print '<br><table class="noborder" width="100%">'; + print '<tr class="liste_titre">'; + print '<td>'.$langs->trans('ExpenseReport').'</td>'; + print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>'; + print '<td align="center">'.$langs->trans('Status').'</td>'; + print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>'; + print "</tr>\n"; + + if ($num > 0) + { + $var=True; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $var=!$var; + print '<tr '.$bc[$var].'>'; + // Ref + print '<td>'; + $expensereport->fetch($objp->did); + print $expensereport->getNomUrl(1); + print "</td>\n"; + // Expected to pay + print '<td align="right">'.price($objp->total_ttc).'</td>'; + // Status + print '<td align="center">'.$expensereport->getLibStatut(4,$objp->amount).'</td>'; + // Amount paid + print '<td align="right">'.price($objp->amount).'</td>'; + print "</tr>\n"; + if ($objp->paid == 1) // If at least one invoice is paid, disable delete + { + $disable_delete = 1; + } + $total = $total + $objp->amount; + $i++; + } + } + $var=!$var; + + print "</table>\n"; + $db->free($resql); +} +else +{ + dol_print_error($db); +} + +print '</div>'; + + +/* + * Actions buttons + */ +print '<div class="tabsAction">'; + +/* +if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) +{ + if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '') + { + if ($user->rights->facture->paiement) + { + print '<a class="butAction" href="card.php?id='.$_GET['id'].'&facid='.$objp->facid.'&action=valide">'.$langs->trans('Valid').'</a>'; + } + } +} +*/ + +if ($_GET['action'] == '') +{ + if ($user->rights->expensereport->supprimer) + { + if (! $disable_delete) + { + print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&action=delete">'.$langs->trans('Delete').'</a>'; + } + else + { + print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>'; + } + } +} + +print '</div>'; + + + +llxFooter(); + +$db->close(); diff --git a/htdocs/expensereport/payment/index.html b/htdocs/expensereport/payment/index.html new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/htdocs/expensereport/payment/payment.php b/htdocs/expensereport/payment/payment.php new file mode 100644 index 0000000000000000000000000000000000000000..7b867609f4fdb655f77ad33d685fd4e384b79269 --- /dev/null +++ b/htdocs/expensereport/payment/payment.php @@ -0,0 +1,314 @@ +<?php +/* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file htdocs/expensereport/payment/payment.php + * \ingroup Expense Report + * \brief Page to add payment of an expense report + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load("bills"); + +$chid=GETPOST("id"); +$action=GETPOST('action'); +$amounts = array(); + +// Security check +$socid=0; +if ($user->societe_id > 0) +{ + $socid = $user->societe_id; +} + + +/* + * Actions + */ + +if ($action == 'add_payment') +{ + $error=0; + + if ($_POST["cancel"]) + { + $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$chid; + header("Location: ".$loc); + exit; + } + + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + + if (! $_POST["fk_typepayment"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); + $error++; + } + if ($datepaid == '') + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")); + $error++; + } + if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")); + $error++; + } + + if (! $error) + { + $paymentid = 0; + + // Read possible payments + foreach ($_POST as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $other_chid = substr($key,7); + $amounts[$other_chid] = price2num($_POST[$key]); + } + } + + if (count($amounts) <= 0) + { + $error++; + $errmsg='ErrorNoPaymentDefined'; + } + + if (! $error) + { + $db->begin(); + + // Create a line of payments + $payment = new PaymentExpenseReport($db); + $payment->chid = $chid; + $payment->datepaid = $datepaid; + $payment->amounts = $amounts; // Tableau de montant + $payment->fk_typepayment = $_POST["fk_typepayment"]; + $payment->num_payment = $_POST["num_payment"]; + $payment->note = $_POST["note"]; + + if (! $error) + { + $paymentid = $payment->create($user); + if ($paymentid < 0) + { + $errmsg=$payment->error; + $error++; + } + } + + if (! $error) + { + $result=$payment->addPaymentToBank($user,'payment_expensereport','(ExpenseReportPayment)',$_POST['accountid'],'',''); + if (! $result > 0) + { + $errmsg=$payment->error; + $error++; + } + } + + if (! $error) + { + $db->commit(); + $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$chid; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } + } + + $_GET["action"]='create'; +} + + +/* + * View + */ + +llxHeader(); + +$form=new Form($db); + + +// Form to create expense report payment +if (GETPOST("action") == 'create') +{ + + $expensereport = new ExpenseReport($db); + $expensereport->fetch($chid); + + $total = $expensereport->total_ttc; + + print_fiche_titre($langs->trans("DoPayment")); + + if ($mesg) + { + print "<div class=\"error\">$mesg</div>"; + } + + print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">'; + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; + print '<input type="hidden" name="id" value="'.$chid.'">'; + print '<input type="hidden" name="chid" value="'.$chid.'">'; + print '<input type="hidden" name="action" value="add_payment">'; + + dol_fiche_head(); + + print '<table cellspacing="0" class="border" width="100%" cellpadding="2">'; + + print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("ExpenseReport").'</td>'; + + print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/card.php?id='.$chid.'">'.$expensereport->ref.'</a></td></tr>'; + print '<tr><td>'.$langs->trans("Period").'</td><td colspan="2">'.get_date_range($expensereport->date_debut,$expensereport->date_fin,"",$langs,0).'</td></tr>'; + print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'.price($expensereport->total_ttc,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; + + $sql = "SELECT sum(p.amount) as total"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p"; + $sql.= " WHERE p.fk_expensereport = ".$chid; + $resql = $db->query($sql); + if ($resql) + { + $obj=$db->fetch_object($resql); + $sumpaid = $obj->total; + $db->free(); + } + print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2">'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; + print '<tr><td valign="top">'.$langs->trans("RemainderToPay").'</td><td colspan="2">'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; + + print '<tr class="liste_titre">'; + print "<td colspan=\"3\">".$langs->trans("Payment").'</td>'; + print '</tr>'; + + print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">'; + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaid):0; + $form->select_date($datepayment,'','','','',"add_payment",1,1); + print "</td>"; + print '</tr>'; + + print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td colspan="2">'; + $form->select_types_paiements(isset($_POST["fk_typepayment"])?$_POST["fk_typepayment"]:$expensereport->fk_typepayment, "fk_typepayment"); + print "</td>\n"; + print '</tr>'; + + print '<tr>'; + print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>'; + print '<td colspan="2">'; + $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$expensereport->accountid, "accountid", 0, '',1); // Show open bank account list + print '</td></tr>'; + + // Number + print '<tr><td>'.$langs->trans('Numero'); + print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>'; + print '</td>'; + print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n"; + + print '<tr>'; + print '<td valign="top">'.$langs->trans("Comments").'</td>'; + print '<td valign="top" colspan="2"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>'; + print '</tr>'; + + print '</table>'; + + dol_fiche_end(); + + /* + * Autres charges impayees + */ + $num = 1; + $i = 0; + + print '<table class="noborder" width="100%">'; + print '<tr class="liste_titre">'; + print '<td align="right">'.$langs->trans("Amount").'</td>'; + print '<td align="right">'.$langs->trans("AlreadyPaid").'</td>'; + print '<td align="right">'.$langs->trans("RemainderToPay").'</td>'; + print '<td align="center">'.$langs->trans("Amount").'</td>'; + print "</tr>\n"; + + $var=true; + $total=0; + $totalrecu=0; + + while ($i < $num) + { + $objp = $expensereport; + + $var=!$var; + + print "<tr ".$bc[$var].">"; + + print '<td align="right">'.price($objp->total_ttc)."</td>"; + + print '<td align="right">'.price($sumpaid)."</td>"; + + print '<td align="right">'.price($objp->total_ttc - $sumpaid)."</td>"; + + print '<td align="center">'; + if ($sumpaid < $objp->total_ttc) + { + $namef = "amount_".$objp->id; + print '<input type="text" size="8" name="'.$namef.'">'; + } + else + { + print '-'; + } + print "</td>"; + + print "</tr>\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + if ($i > 1) + { + // Print total + print "<tr ".$bc[!$var].">"; + print '<td colspan="2" align="left">'.$langs->trans("Total").':</td>'; + print "<td align=\"right\"><b>".price($total_ttc)."</b></td>"; + print "<td align=\"right\"><b>".price($totalrecu)."</b></td>"; + print "<td align=\"right\"><b>".price($total_ttc - $totalrecu)."</b></td>"; + print '<td align="center"> </td>'; + print "</tr>\n"; + } + + print "</table>"; + + print '<br><div class="center">'; + print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; + print ' '; + print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; + print '</div>'; + + print "</form>\n"; +} + + +$db->close(); + +llxFooter(); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 309622a170d2151e2b119e6898e81c9afbcecf3a..a406ad9c6d0358f87cae22ef84e3f5008dcded2d 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -243,6 +243,7 @@ CREATE TABLE llx_expensereport ( fk_user_paid integer DEFAULT NULL, fk_statut integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé fk_c_paiement integer DEFAULT NULL, + paid smallint default 0 NOT NULL, note_public text, note_private text, detail_refuse varchar(255) DEFAULT NULL, @@ -285,6 +286,22 @@ CREATE TABLE llx_expensereport_det ALTER TABLE llx_expensereport_det MODIFY COLUMN fk_projet integer NULL; ALTER TABLE llx_expensereport_det MODIFY COLUMN fk_c_tva integer NULL; +create table llx_payment_expensereport +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_expensereport integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user +)ENGINE=innodb; + ALTER TABLE llx_projet ADD COLUMN budget_amount double(24,8); -- Alias names (commercial, trademark or alias names) diff --git a/htdocs/install/mysql/tables/llx_expensereport.sql b/htdocs/install/mysql/tables/llx_expensereport.sql index 657d8f9e278b9624b7de48fb1d07d38c6fbf9c73..879623b6b7e8b6f9e4ccd94c3ab6f1802934ad19 100755 --- a/htdocs/install/mysql/tables/llx_expensereport.sql +++ b/htdocs/install/mysql/tables/llx_expensereport.sql @@ -46,6 +46,7 @@ CREATE TABLE llx_expensereport ( fk_user_paid integer DEFAULT NULL, fk_statut integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé fk_c_paiement integer DEFAULT NULL, + paid smallint default 0 NOT NULL, note_public text, note_private text, detail_refuse varchar(255) DEFAULT NULL, diff --git a/htdocs/install/mysql/tables/llx_payment_expensereport.sql b/htdocs/install/mysql/tables/llx_payment_expensereport.sql new file mode 100644 index 0000000000000000000000000000000000000000..55d10289348e1b53882cfc53d2088acd265e0e4e --- /dev/null +++ b/htdocs/install/mysql/tables/llx_payment_expensereport.sql @@ -0,0 +1,33 @@ +-- =================================================================== +-- Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com> +-- +-- 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 3 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, see <http://www.gnu.org/licenses/>. +-- +-- =================================================================== + +create table llx_payment_expensereport +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_expensereport integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user +)ENGINE=innodb;