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