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
|
<? require("inc/configure.php"); require("inc/global.php"); require("inc/checklogin.php"); if ($logged_in == 0) { //echo 'Not logged in. <a href="login.php">Login</a>'; header('Window-target: _parent'); header('Location: login.php'); exit(); } if (checkObject(16) <> 1){ die("Unauthorized Access"); exit(); } ?> <? $quotationno = $_GET['quotationno'];
$creationdate = date("YmdGis"); $creationby = ""; $orderdate = date("Ymd"); $lineno = 1; $stockmsg = "";
//**header $sql = "select max(invoiceno) as maxinvoiceno from OM_INVOICE_HDR"; $result = mysql_query($sql); if ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { if (strlen($row{'maxinvoiceno'}) == 0) { $invoiceno = 100001; } else { $invoiceno = $row{'maxinvoiceno'} + 1; } } else { $invoiceno = 100001; }
$sql = "insert into OM_INVOICE_HDR (invoiceno, custno, catid, custnameeng, custnamechi, telno, faxno, email, billaddress, shipaddress, attn, remarks , salesid, paymentmethodid, paymenttermid, status, discount, deliverymethod, creationdate, creationby, orderdate , carid, licno, modelno, chassisno, caryear ) select $invoiceno, custno, catid, custnameeng, custnamechi, telno, faxno, email, billaddress, shipaddress, attn, remarks , salesid, paymentmethodid, paymenttermid, 1, discount, deliverymethod, '$creationdate', '$creationby', '$orderdate' , carid, licno, modelno, chassisno, caryear from OM_QUOTATION_HDR where quotationno = $quotationno ";
$result = mysql_query($sql);
if (!$result) { die('Invalid query: ' . mysql_error()); }
//**detail $sql = "select a.prodid, a.prodname, a.description, a.uomid, a.uom, a.qty, a.price, a.discount, a.amount, typeid, a.cost, a.prodno from OM_QUOTATION_DTL a , INV_PRODUCT b where quotationno = $quotationno and a.prodid = b.prodid order by lineno "; $result = mysql_query($sql); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $soh = getSOH($row{'prodid'}); $flag = 0; if ($row{'typeid'}==1) { //if ($soh >= $row{'qty'}) //{ $flag = 1; //} //else //{ //$stockmsg = $stockmsg ."(". $row{'prodid'} .") "; //} } else { $flag = 1; }
if ($flag == 1) { //$cost = isnull(getCOST($row{'prodid'}),0);
$sqli = " insert into OM_INVOICE_DTL (invoiceno, lineno, prodid, prodname, description, uomid, uom, qty, price, cost, discount, amount, prodno) values ($invoiceno, $lineno, ".$row{'prodid'}.", '".$row{'prodname'}."', '".$row{'description'}."', ".isnull($row{'uomid'},0).", '".isnull($row{'uom'},0)."' , ".isnull($row{'qty'},0).", ".isnull($row{'price'},0).", ".isnull($row{'cost'},0).", ".isnull($row{'discount'},0).", ".isnull($row{'amount'},0).", ".$row['prodno'].") "; $resulti = mysql_query($sqli);
if (!$resulti) { die('Invalid query: ' . mysql_error()); }
$sqli = " insert into INV_STOCK_TRANSACTION (prodid, qty, uomid, stocktrantypeid, sign, docno, lineno, creationdate, creationby) select ".$row{'prodid'}.", ".isnull($row{'qty'},0).", ".isnull($row{'uomid'},0).", 2, -1, '$invoiceno', $lineno, '$creationdate', '$creationby' from INV_PRODUCT where prodid = ".$row{'prodid'}." and typeid = 1 "; $resulti = mysql_query($sqli);
if (!$resulti) { die('Invalid query: ' . mysql_error()); }
$lineno++; } $msg = "Copy successful!"; }
//if (strlen($stockmsg)<>0) //{ //$msg = $msg." Insufficient stock: ". $stockmsg; //} header("Location: invoicedetail.php?invoiceno=$invoiceno&msg=$msg"); ?>
|