PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fourn/paiement/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 344 lines | 236 code | 55 blank | 53 comment | 65 complexity | e39de160fb1043f039fe7095900fda48 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  4. * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/fourn/paiement/fiche.php
  21. * \ingroup facture, fournisseur
  22. * \brief Tab to show a payment of a supplier invoice
  23. * \remarks Fichier presque identique a compta/paiement/fiche.php
  24. */
  25. require '../../main.inc.php';
  26. require DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  27. require DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  28. require DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  29. $langs->load('bills');
  30. $langs->load('banks');
  31. $langs->load('companies');
  32. $langs->load("suppliers");
  33. $mesg='';
  34. $id = GETPOST('id','int');
  35. $action = GETPOST('action','alpha');
  36. $confirm = GETPOST('confirm','alpha');
  37. $object = new PaiementFourn($db);
  38. /*
  39. * Actions
  40. */
  41. if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
  42. {
  43. $db->begin();
  44. $object->fetch($id);
  45. $result = $object->update_note(GETPOST('note'));
  46. if ($result > 0)
  47. {
  48. $db->commit();
  49. $action='';
  50. }
  51. else
  52. {
  53. $mesg='<div class="error">'.$object->error.'</div>';
  54. $db->rollback();
  55. }
  56. }
  57. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
  58. {
  59. $db->begin();
  60. $object->fetch($id);
  61. $result = $object->delete();
  62. if ($result > 0)
  63. {
  64. $db->commit();
  65. header('Location: '.DOL_URL_ROOT.'/fourn/facture/paiement.php');
  66. exit;
  67. }
  68. else
  69. {
  70. $mesg='<div class="error">'.$object->error.'</div>';
  71. $db->rollback();
  72. }
  73. }
  74. if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->fournisseur->facture->valider)
  75. {
  76. $db->begin();
  77. $object->fetch($id);
  78. if ($object->valide() >= 0)
  79. {
  80. $db->commit();
  81. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
  82. exit;
  83. }
  84. else
  85. {
  86. $mesg='<div class="error">'.$object->error.'</div>';
  87. $db->rollback();
  88. }
  89. }
  90. if ($action == 'setnum' && ! empty($_POST['num_paiement']))
  91. {
  92. $object->fetch($id);
  93. $res = $object->update_num($_POST['num_paiement']);
  94. if ($res === 0)
  95. {
  96. $mesg = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
  97. }
  98. else
  99. {
  100. $mesg = '<div class="error">'.$langs->trans('PaymentNumberUpdateFailed').'</div>';
  101. }
  102. }
  103. if ($action == 'setdate' && ! empty($_POST['datepday']))
  104. {
  105. $object->fetch($id);
  106. $datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']);
  107. $res = $object->update_date($datepaye);
  108. if ($res === 0)
  109. {
  110. $mesg = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
  111. }
  112. else
  113. {
  114. $mesg = '<div class="error">'.$langs->trans('PaymentDateUpdateFailed').'</div>';
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. llxHeader();
  121. $form = new Form($db);
  122. $h=0;
  123. $head[$h][0] = $_SERVER['PHP_SELF'].'?id='.$id;
  124. $head[$h][1] = $langs->trans('Card');
  125. $hselected = $h;
  126. $h++;
  127. $head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$id;
  128. $head[$h][1] = $langs->trans('Info');
  129. $h++;
  130. dol_fiche_head($head, $hselected, $langs->trans('SupplierPayment'), 0, 'payment');
  131. $result=$object->fetch($id);
  132. if ($result > 0)
  133. {
  134. /*
  135. * Confirmation de la suppression du paiement
  136. */
  137. if ($action == 'delete')
  138. {
  139. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
  140. if ($ret == 'html') print '<br>';
  141. }
  142. /*
  143. * Confirmation de la validation du paiement
  144. */
  145. if ($action == 'valide')
  146. {
  147. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide');
  148. if ($ret == 'html') print '<br>';
  149. }
  150. print '<table class="border" width="100%">';
  151. print '<tr>';
  152. print '<td valign="top" width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">';
  153. print $form->showrefnav($object,'id','',1,'rowid','ref');
  154. print '</td></tr>';
  155. // Date payment
  156. print '<tr><td valign="top" colspan="2">'.$form->editfieldkey("Date",'datep',$object->date,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  157. print $form->editfieldval("Date",'datep',$object->date,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'datepicker','',null,$langs->trans('PaymentDateUpdateSucceeded'));
  158. print '</td></tr>';
  159. // Payment mode
  160. print '<tr><td valign="top" colspan="2">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$object->type_libelle.'</td></tr>';
  161. // Payment numero
  162. print '<tr><td valign="top" colspan="2">'.$form->editfieldkey("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  163. print $form->editfieldval("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
  164. print '</td></tr>';
  165. // Amount
  166. print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant).'&nbsp;'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
  167. if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  168. {
  169. print '<tr><td valign="top" colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
  170. }
  171. // Note
  172. print '<tr><td valign="top"" colspan="2">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  173. print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->fournisseur->facture->creer,'textarea');
  174. print '</td></tr>';
  175. // Bank account
  176. if (! empty($conf->banque->enabled))
  177. {
  178. if ($object->bank_account)
  179. {
  180. $bankline=new AccountLine($db);
  181. $bankline->fetch($object->bank_line);
  182. print '<tr>';
  183. print '<td colspan="2">'.$langs->trans('BankTransactionLine').'</td>';
  184. print '<td colspan="3">';
  185. print $bankline->getNomUrl(1,0,'showall');
  186. print '</td>';
  187. print '</tr>';
  188. }
  189. }
  190. print '</table>';
  191. dol_htmloutput_mesg($mesg);
  192. print '<br>';
  193. /**
  194. * Liste des factures
  195. */
  196. $allow_delete = 1 ;
  197. $sql = 'SELECT f.rowid as ref, f.facnumber as ref_supplier, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.rowid as socid';
  198. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
  199. $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
  200. $sql .= ' AND pf.fk_paiementfourn = '.$object->id;
  201. $resql=$db->query($sql);
  202. if ($resql)
  203. {
  204. $num = $db->num_rows($resql);
  205. $i = 0;
  206. $total = 0;
  207. print '<b>'.$langs->trans("Invoices").'</b><br>';
  208. print '<table class="noborder" width="100%">';
  209. print '<tr class="liste_titre">';
  210. print '<td>'.$langs->trans('Ref').'</td>';
  211. print '<td>'.$langs->trans('RefSupplier').'</td>';
  212. print '<td>'.$langs->trans('Company').'</td>';
  213. print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
  214. print '<td align="center">'.$langs->trans('Status').'</td>';
  215. print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
  216. print "</tr>\n";
  217. if ($num > 0)
  218. {
  219. $var=True;
  220. $facturestatic=new FactureFournisseur($db);
  221. while ($i < $num)
  222. {
  223. $objp = $db->fetch_object($resql);
  224. $var=!$var;
  225. print '<tr '.$bc[$var].'>';
  226. // Ref
  227. print '<td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' ';
  228. print $objp->ref;
  229. print "</a></td>\n";
  230. // Ref supplier
  231. print '<td>'.$objp->ref_supplier."</td>\n";
  232. // Third party
  233. print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
  234. // Expected to pay
  235. print '<td align="right">'.price($objp->total_ttc).'</td>';
  236. // Status
  237. print '<td align="center">'.$facturestatic->LibStatut($objp->paye,$objp->fk_statut,2,1).'</td>';
  238. // Payed
  239. print '<td align="right">'.price($objp->amount).'</td>';
  240. print "</tr>\n";
  241. if ($objp->paye == 1)
  242. {
  243. $allow_delete = 0;
  244. }
  245. $total = $total + $objp->amount;
  246. $i++;
  247. }
  248. }
  249. $var=!$var;
  250. print "</table>\n";
  251. $db->free($resql);
  252. }
  253. else
  254. {
  255. dol_print_error($db);
  256. }
  257. print '</div>';
  258. /*
  259. * Boutons Actions
  260. */
  261. print '<div class="tabsAction">';
  262. if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  263. {
  264. if ($user->societe_id == 0 && $object->statut == 0 && $action == '')
  265. {
  266. if ($user->rights->fournisseur->facture->valider)
  267. {
  268. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  269. }
  270. }
  271. }
  272. if ($user->societe_id == 0 && $allow_delete && $object->statut == 0 && $action == '')
  273. {
  274. if ($user->rights->fournisseur->facture->supprimer)
  275. {
  276. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  277. }
  278. }
  279. print '</div>';
  280. }
  281. else
  282. {
  283. $langs->load("errors");
  284. print $langs->trans("ErrorRecordNotFound");
  285. }
  286. dol_fiche_end();
  287. llxFooter();
  288. $db->close();
  289. ?>