PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/chronique/OffersReceived.php

http://chronique.googlecode.com/
PHP | 277 lines | 266 code | 10 blank | 1 comment | 15 complexity | c455f33c577f2bde4881e20fa152dd1b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /*$Id: OffersReceived.php 4500 2011-02-27 09:18:42Z daintree $ */
  3. include('includes/session.inc');
  4. $title = _('Supplier Offers');
  5. include('includes/header.inc');
  6. include('includes/SQL_CommonFunctions.inc');
  7. if (isset($_POST['supplierid'])) {
  8. $sql="SELECT suppname,
  9. email,
  10. currcode,
  11. paymentterms
  12. FROM suppliers
  13. WHERE supplierid='".$_POST['supplierid']."'";
  14. $result = DB_query($sql, $db);
  15. $myrow=DB_fetch_array($result);
  16. $SupplierName=$myrow['suppname'];
  17. $Email=$myrow['email'];
  18. $CurrCode=$myrow['currcode'];
  19. $PaymentTerms=$myrow['paymentterms'];
  20. }
  21. if (!isset($_POST['supplierid'])) {
  22. $sql="SELECT DISTINCT
  23. offers.supplierid,
  24. suppliers.suppname
  25. FROM offers
  26. LEFT JOIN purchorderauth
  27. ON offers.currcode=purchorderauth.currabrev
  28. LEFT JOIN suppliers
  29. ON suppliers.supplierid=offers.supplierid
  30. WHERE purchorderauth.userid='".$_SESSION['UserID']."'
  31. AND offers.expirydate>'".date('Y-m-d')."'
  32. AND purchorderauth.cancreate=0";
  33. $result=DB_query($sql, $db);
  34. if (DB_num_rows($result)==0) {
  35. prnMsg(_('There are no offers outstanding that you are authorised to deal with'), 'information');
  36. } else {
  37. echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' .
  38. _('Select Supplier') . '" alt="" />' . ' ' . _('Select Supplier') . '</p>';
  39. echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) .'">';
  40. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  41. echo '<table class="selection">
  42. <tr>
  43. <td>'._('Select Supplier').'</td>
  44. <td><select name=supplierid>';
  45. while ($myrow=DB_fetch_array($result)) {
  46. echo '<option value="'.$myrow['supplierid'].'">'.$myrow['suppname'].'</option>';
  47. }
  48. echo '</select></td>
  49. </tr>
  50. <tr><td colspan="12">
  51. <div class="centre">
  52. <input type=submit name=select value=' . _('Enter Information') . '>
  53. </div>
  54. </td>
  55. </tr>
  56. </table>
  57. </form>';
  58. }
  59. }
  60. if (!isset($_POST['submit']) and isset($_POST['supplierid'])) {
  61. $sql = "SELECT offers.offerid,
  62. offers.tenderid,
  63. offers.supplierid,
  64. suppliers.suppname,
  65. offers.stockid,
  66. stockmaster.description,
  67. offers.quantity,
  68. offers.uom,
  69. offers.price,
  70. offers.expirydate,
  71. offers.currcode,
  72. stockmaster.decimalplaces,
  73. currencies.decimalplaces AS currdecimalplaces
  74. FROM offers INNER JOIN purchorderauth
  75. ON offers.currcode=purchorderauth.currabrev
  76. INNER JOIN suppliers
  77. ON suppliers.supplierid=offers.supplierid
  78. INNER JOIN currencies
  79. ON suppliers.currcode=currencies.currabrev
  80. LEFT JOIN stockmaster
  81. ON stockmaster.stockid=offers.stockid
  82. WHERE purchorderauth.userid='" . $_SESSION['UserID'] . "'
  83. AND offers.expirydate>'" . date('Y-m-d') . "'
  84. AND offers.supplierid='" . $_POST['supplierid'] . "'
  85. ORDER BY offerid";
  86. $result=DB_query($sql, $db);
  87. echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '">';
  88. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  89. echo '<p class="page_title_text">
  90. <img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Supplier Offers') . '" alt="" />' . ' ' . _('Supplier Offers') . '
  91. </p>';
  92. echo '<table class="selection">
  93. <tr>
  94. <th>'._('Offer ID').'</th>
  95. <th>'._('Supplier').'</th>
  96. <th>'._('Stock Item').'</th>
  97. <th>'._('Quantity').'</th>
  98. <th>'._('Units').'</th>
  99. <th>'._('Price').'</th>
  100. <th>'._('Total').'</th>
  101. <th>'._('Currency').'</th>
  102. <th>'._('Offer Expires').'</th>
  103. <th>'._('Accept').'</th>
  104. <th>'._('Reject').'</th>
  105. <th>'._('Defer').'</th>
  106. </tr>';
  107. $k=0;
  108. while ($myrow=DB_fetch_array($result)) {
  109. if ($k==1){
  110. echo '<tr class="EvenTableRows">';
  111. $k=0;
  112. } else {
  113. echo '<tr class="OddTableRows">';
  114. $k++;
  115. }
  116. echo '<td>'.$myrow['offerid'].'</td>
  117. <td>'.$myrow['suppname'].'</td>
  118. <td>'.$myrow['description'].'</td>
  119. <td class="number">'.locale_number_format($myrow['quantity'],$myrow['decimalplaces']).'</td>
  120. <td>'.$myrow['uom'].'</td>
  121. <td class="number">'.locale_number_format($myrow['price'],$myrow['currdecimalplaces']).'</td>
  122. <td class="number">'.locale_number_format($myrow['price']*$myrow['quantity'],$myrow['currdecimalplaces']).'</td>
  123. <td>'.$myrow['currcode'].'</td>
  124. <td>'.$myrow['expirydate'].'</td>
  125. <td><input type="radio" name="action'.$myrow['offerid'].'" value="1" /></td>
  126. <td><input type="radio" name="action'.$myrow['offerid'].'" value="2" /></td>
  127. <td><input type="radio" checked name="action'.$myrow['offerid'].'" value="3" /></td>
  128. <td><input type="hidden" name="supplierid" value="'.$myrow['supplierid'].'" /></td>
  129. </tr>';
  130. }
  131. echo '<tr>
  132. <td colspan="12">
  133. <div class="centre">
  134. <input type="submit" name="submit" value=' . _('Enter Information') . '>
  135. </div>
  136. </td>
  137. </tr>
  138. </form>
  139. </table>';
  140. } else if(isset($_POST['submit']) and isset($_POST['supplierid'])) {
  141. include ('includes/htmlMimeMail.php');
  142. $accepts=array();
  143. $rejects=array();
  144. $defers=array();
  145. foreach ($_POST as $key => $value) {
  146. if(mb_substr($key,0,6)=='action') {
  147. $OfferID=mb_substr($key,6);
  148. switch ($value) {
  149. case 1:
  150. $accepts[]=$OfferID;
  151. break;
  152. case 2:
  153. $rejects[]=$OfferID;
  154. break;
  155. case 3:
  156. $defers[]=$OfferID;
  157. break;
  158. }
  159. }
  160. }
  161. if (sizeOf($accepts)>0){
  162. $MailText=_('This email has been automatically generated by the webERP installation at').' '.
  163. $_SESSION['CompanyRecord']['coyname']."\n";
  164. $MailText.=_('The following offers you made have been accepted')."\n";
  165. $MailText.=_('An official order will be sent to you in due course')."\n\n";
  166. $sql="SELECT rate FROM currencies where currabrev='" . $CurrCode ."'";
  167. $result=DB_query($sql, $db);
  168. $myrow=DB_fetch_array($result);
  169. $Rate=$myrow['rate'];
  170. $OrderNo = GetNextTransNo(18, $db);
  171. $sql="INSERT INTO purchorders (
  172. orderno,
  173. supplierno,
  174. orddate,
  175. rate,
  176. initiator,
  177. intostocklocation,
  178. deliverydate,
  179. status,
  180. stat_comment,
  181. paymentterms)
  182. VALUES (
  183. '".$OrderNo."',
  184. '".$_POST['supplierid']."',
  185. '".date('Y-m-d')."',
  186. '".$Rate."',
  187. '".$_SESSION['UserID']."',
  188. '".$_SESSION['DefaultFactoryLocation']."',
  189. '".date('Y-m-d')."',
  190. '"._('Pending')."',
  191. '"._('Automatically generated from tendering system')."',
  192. '".$PaymentTerms."')";
  193. DB_query($sql, $db);
  194. foreach ($accepts as $AcceptID) {
  195. $sql="SELECT offers.quantity,
  196. offers.price,
  197. offers.uom,
  198. stockmaster.description,
  199. stockmaster.stockid
  200. FROM offers
  201. LEFT JOIN stockmaster
  202. ON offers.stockid=stockmaster.stockid
  203. WHERE offerid='".$AcceptID."'";
  204. $result= DB_query($sql, $db);
  205. $myrow=DB_fetch_array($result);
  206. $MailText.=$myrow['description']."\t"._('Quantity').' '.$myrow['quantity']."\t"._('Price').' '.
  207. locale_number_format($myrow['price'])."\n";
  208. $sql="INSERT INTO purchorderdetails (orderno,
  209. itemcode,
  210. deliverydate,
  211. itemdescription,
  212. unitprice,
  213. actprice,
  214. quantityord,
  215. suppliersunit)
  216. VALUES ('".$OrderNo."',
  217. '".$myrow['stockid']."',
  218. '".date('Y-m-d')."',
  219. '".$myrow['description']."',
  220. '".$myrow['price']."',
  221. '".$myrow['price']."',
  222. '".$myrow['quantity']."',
  223. '".$myrow['uom']."')";
  224. $result=DB_query($sql, $db);
  225. $sql="DELETE FROM offers WHERE offerid='".$AcceptID."'";
  226. $result=DB_query($sql, $db);
  227. }
  228. $mail = new htmlMimeMail();
  229. $mail->setSubject(_('Your offer to').' '.$_SESSION['CompanyRecord']['coyname'].' '._('has been accepted'));
  230. $mail->setText($MailText);
  231. $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>');
  232. $result = $mail->send(array($Email), 'smtp');
  233. prnMsg(_('The accepted offers from').' '.$SupplierName.' '._('have been converted to purchase orders and an email sent to')
  234. .' '.$Email."\n"._('Please review the order contents').' '.'<a href="'.$rootpath .
  235. '/PO_Header.php?ModifyOrderNumber=' . $OrderNo.'">'._('here').'</a>', 'success');
  236. }
  237. if (sizeOf($rejects)>0){
  238. $MailText=_('This email has been automatically generated by the webERP installation at').' '.
  239. $_SESSION['CompanyRecord']['coyname']."\n";
  240. $MailText.=_('The following offers you made have been rejected')."\n\n";
  241. foreach ($rejects as $RejectID) {
  242. $sql="SELECT offers.quantity,
  243. offers.price,
  244. stockmaster.description
  245. FROM offers
  246. LEFT JOIN stockmaster
  247. ON offers.stockid=stockmaster.stockid
  248. WHERE offerid='".$RejectID."'";
  249. $result= DB_query($sql, $db);
  250. $myrow=DB_fetch_array($result);
  251. $MailText.=$myrow['description']."\t"._('Quantity').' '.$myrow['quantity']."\t"._('Price').' '.
  252. locale_number_format($myrow['price'])."\n";
  253. $sql="DELETE FROM offers WHERE offerid='".$RejectID."'";
  254. $result=DB_query($sql, $db);
  255. }
  256. $mail = new htmlMimeMail();
  257. $mail->setSubject(_('Your offer to').' '.$_SESSION['CompanyRecord']['coyname'].' '._('has been rejected'));
  258. $mail->setText($MailText);
  259. $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>');
  260. $result = $mail->send(array($Email), 'smtp');
  261. prnMsg(_('The rejected offers from').' '.$SupplierName.' '._('have been removed from the system and an email sent to')
  262. .' '.$Email, 'success');
  263. }
  264. prnMsg(_('All offers have been processed, and emails sent where appropriate'), 'success');
  265. }
  266. include('includes/footer.inc');
  267. ?>