forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectContract.php
203 lines (173 loc) · 6.53 KB
/
SelectContract.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
<?php
include('includes/session.php');
$Title = _('Select Contract');
$ViewTopic= 'Contracts';
$BookMark = 'SelectContract';
include('includes/header.php');
echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/contract.png" title="', // Icon image.
_('Contracts'), '" /> ', // Icon title.
_('Select A Contract'), '</p>';// Page title.
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<br /><div class="centre">';
if (isset($_GET['ContractRef'])){
$_POST['ContractRef']=$_GET['ContractRef'];
}
if (isset($_GET['SelectedCustomer'])){
$_POST['SelectedCustomer']=$_GET['SelectedCustomer'];
}
if (isset($_POST['ContractRef']) AND $_POST['ContractRef']!='') {
$_POST['ContractRef'] = trim($_POST['ContractRef']);
echo _('Contract Reference') . ' - ' . $_POST['ContractRef'];
} else {
if (isset($_POST['SelectedCustomer'])) {
echo _('For customer') . ': ' . $_POST['SelectedCustomer'] . ' ' . _('and') . ' ';
echo '<input type="hidden" name="SelectedCustomer" value="' . $_POST['SelectedCustomer'] . '" />';
}
}
if (!isset($_POST['ContractRef']) or $_POST['ContractRef']==''){
echo _('Contract Reference') . ': <input type="text" name="ContractRef" maxlength="20" size="20" /> ';
echo '<select name="Status">';
if (isset($_GET['Status'])){
$_POST['Status']=$_GET['Status'];
}
if (!isset($_POST['Status'])){
$_POST['Status']=4;
}
$statuses[] = _('Not Yet Quoted');
$statuses[] = _('Quoted - No Order Placed');
$statuses[] = _('Order Placed');
$statuses[] = _('Completed');
$statuses[] = _('All Contracts');
$status_count = count($statuses);
for ( $i = 0; $i < $status_count; $i++ ) {
if ( $i == $_POST['Status'] ) {
echo '<option selected="selected" value="' . $i . '">' . $statuses[$i] . '</option>';
} else {
echo '<option value="' . $i . '">' . $statuses[$i] . '</option>';
}
}
echo '</select> ';
}
echo '<input type="submit" name="SearchContracts" value="' . _('Search') . '" />';
echo ' <a href="' . $RootPath . '/Contracts.php">' . _('New Contract') . '</a></div><br />';
//figure out the SQL required from the inputs available
if (isset($_POST['ContractRef']) AND $_POST['ContractRef'] !='') {
$SQL = "SELECT contractref,
contractdescription,
categoryid,
contracts.debtorno,
debtorsmaster.name AS customername,
branchcode,
status,
orderno,
wo,
customerref,
requireddate
FROM contracts INNER JOIN debtorsmaster
ON contracts.debtorno = debtorsmaster.debtorno
INNER JOIN locationusers ON locationusers.loccode=contracts.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE contractref " . LIKE . " '%" . $_POST['ContractRef'] ."%'";
} else { //contractref not selected
if (isset($_POST['SelectedCustomer'])) {
$SQL = "SELECT contractref,
contractdescription,
categoryid,
contracts.debtorno,
debtorsmaster.name AS customername,
branchcode,
status,
orderno,
wo,
customerref,
requireddate
FROM contracts INNER JOIN debtorsmaster
ON contracts.debtorno = debtorsmaster.debtorno
INNER JOIN locationusers ON locationusers.loccode=contracts.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1
WHERE debtorno='". $_POST['SelectedCustomer'] ."'";
if ($_POST['Status']!=4){
$SQL .= " AND status='" . $_POST['Status'] . "'";
}
} else { //no customer selected
$SQL = "SELECT contractref,
contractdescription,
categoryid,
contracts.debtorno,
debtorsmaster.name AS customername,
branchcode,
status,
orderno,
wo,
customerref,
requireddate
FROM contracts INNER JOIN debtorsmaster
ON contracts.debtorno = debtorsmaster.debtorno
INNER JOIN locationusers ON locationusers.loccode=contracts.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1";
if ($_POST['Status']!=4){
$SQL .= " AND status='" . $_POST['Status'] . "'";
}
}
} //end not contract ref selected
$ErrMsg = _('No contracts were returned by the SQL because');
$ContractsResult = DB_query($SQL,$ErrMsg);
/*show a table of the contracts returned by the SQL */
echo '<table cellpadding="2" width="98%" class="selection">';
$TableHeader = '<tr>
<th>' . _('Modify') . '</th>
<th>' . _('Order') . '</th>
<th>' . _('Issue To WO') . '</th>
<th>' . _('Costing') . '</th>
<th>' . _('Contract Ref') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Customer') . '</th>
<th>' . _('Required Date') . '</th>
</tr>';
echo $TableHeader;
$j = 1;
while ($myrow=DB_fetch_array($ContractsResult)) {
echo '<tr class="striped_row">';
$ModifyPage = $RootPath . '/Contracts.php?ModifyContractRef=' . $myrow['contractref'];
$OrderModifyPage = $RootPath . '/SelectOrderItems.php?ModifyOrderNumber=' . $myrow['orderno'];
$IssueToWOPage = $RootPath . '/WorkOrderIssue.php?WO=' . $myrow['wo'] . '&StockID=' . $myrow['contractref'];
$CostingPage = $RootPath . '/ContractCosting.php?SelectedContract=' . $myrow['contractref'];
$FormatedRequiredDate = ConvertSQLDate($myrow['requireddate']);
if ($myrow['status']==0 OR $myrow['status']==1){ //still setting up the contract
echo '<td><a href="' . $ModifyPage . '">' . _('Modify') . '</a></td>';
} else {
echo '<td>' . _('n/a') . '</td>';
}
if ($myrow['status']==1 OR $myrow['status']==2){ // quoted or ordered
echo '<td><a href="' . $OrderModifyPage . '">' . $myrow['orderno'] . '</a></td>';
} else {
echo '<td>' . _('n/a') . '</td>';
}
if ($myrow['status']==2){ //the customer has accepted the quote but not completed contract yet
echo '<td><a href="' . $IssueToWOPage . '">' . $myrow['wo'] . '</a></td>';
} else {
echo '<td>' . _('n/a') . '</td>';
}
if ($myrow['status']==2 OR $myrow['status']==3){
echo '<td><a href="' . $CostingPage . '">' . _('View') . '</a></td>';
} else {
echo '<td>' . _('n/a') . '</td>';
}
echo '<td>' . $myrow['contractref'] . '</td>
<td>' . $myrow['contractdescription'] . '</td>
<td>' . $myrow['customername'] . '</td>
<td>' . $FormatedRequiredDate . '</td></tr>';
$j++;
if ($j == 12){
$j=1;
echo $TableHeader;
}
//end of page full new headings if
}
//end of while loop
echo '</table>
</div>
</form>
<br />';
include('includes/footer.php');
?>