forked from KwaMoja/KwaMoja
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCOGSGLPostings.php
211 lines (176 loc) · 7.35 KB
/
COGSGLPostings.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
<?php
include ('includes/session.php');
$Title = _('Cost Of Sales GL Postings Set Up');
$ViewTopic = 'CreatingNewSystem';
$BookMark = 'SalesGLPostings';
include ('includes/header.php');
if (isset($_POST['SelectedCOGSPostingID'])) {
$SelectedCOGSPostingID = $_POST['SelectedCOGSPostingID'];
} elseif (isset($_GET['SelectedCOGSPostingID'])) {
$SelectedCOGSPostingID = $_GET['SelectedCOGSPostingID'];
}
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/maintenance.png" title="', _('Search'), '" alt="" />', ' ', $Title, '
</p>';
if (isset($_POST['submit'])) {
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
if (isset($SelectedCOGSPostingID)) {
/*SelectedCOGSPostingID could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
$SQL = "UPDATE cogsglpostings SET
glcode = '" . $_POST['GLCode'] . "',
area = '" . $_POST['Area'] . "',
stkcat = '" . $_POST['StkCat'] . "',
salestype='" . $_POST['SalesType'] . "'
WHERE id ='" . $SelectedCOGSPostingID . "'";
$Msg = _('Cost of sales GL posting code has been updated');
} else {
/*Selected Sales GL Posting is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new SalesGLPosting form */
$SQL = "INSERT INTO cogsglpostings (
glcode,
area,
stkcat,
salestype)
VALUES (
'" . $_POST['GLCode'] . "',
'" . $_POST['Area'] . "',
'" . $_POST['StkCat'] . "',
'" . $_POST['SalesType'] . "'
)";
$Msg = _('A new cost of sales posting code has been inserted') . '.';
}
//run the SQL from either of the above possibilites
$Result = DB_query($SQL);
prnMsg($Msg, 'success');
unset($SelectedCOGSPostingID);
unset($_POST['GLCode']);
unset($_POST['Area']);
unset($_POST['StkCat']);
unset($_POST['SalesType']);
} elseif (isset($_GET['delete'])) {
//the link to delete a selected record was clicked instead of the submit button
$SQL = "DELETE FROM cogsglpostings WHERE id='" . $SelectedCOGSPostingID . "'";
$Result = DB_query($SQL);
prnMsg(_('The cost of sales posting code record has been deleted'), 'success');
unset($SelectedCOGSPostingID);
}
$SQL = "SELECT cogsglpostings.id,
cogsglpostings.area,
cogsglpostings.stkcat,
cogsglpostings.salestype,
chartmaster.accountname
FROM cogsglpostings
LEFT JOIN chartmaster
ON cogsglpostings.glcode = chartmaster.accountcode
WHERE chartmaster.language='" . $_SESSION['ChartLanguage'] . "'
ORDER BY cogsglpostings.area,
cogsglpostings.stkcat,
cogsglpostings.salestype";
$Result = DB_query($SQL);
if (DB_num_rows($Result) > 0) {
echo '<table>
<thead>
<tr>
<th class="SortedColumn">', _('Area'), '</th>
<th class="SortedColumn">', _('Stock Category'), '</th>
<th class="SortedColumn">', _('Sales Type'), '</th>
<th class="SortedColumn">', _('COGS Account'), '</th>
<th colspan="2"></th>
</tr>
</thead>';
echo '<tbody>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<tr class="striped_row">
<td>', $MyRow['area'], '</td>
<td>', $MyRow['stkcat'], '</td>
<td>', $MyRow['salestype'], '</td>
<td>', $MyRow['accountname'], '</td>
<td><a href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '?SelectedCOGSPostingID=', urlencode($MyRow['id']), '">', _('Edit'), '</a></td>
<td><a href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '?SelectedCOGSPostingID=', urlencode($MyRow['id']), '&delete=yes" onclick="return MakeConfirm(\'', _('Are you sure you wish to delete this COGS GL posting record?'), '\', \'Confirm Delete\', this);">', _('Delete'), '</a></td>
</tr>';
} //end while
echo '</tbody>
</table>';
}
echo '<form method="post" action="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
if (isset($SelectedCOGSPostingID)) {
//editing an existing cost of sales posting record
$SQL = "SELECT stkcat,
glcode,
area,
salestype
FROM cogsglpostings
WHERE id='" . $SelectedCOGSPostingID . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['GLCode'] = $MyRow['glcode'];
$_POST['Area'] = $MyRow['area'];
$_POST['StkCat'] = $MyRow['stkcat'];
$_POST['SalesType'] = $MyRow['salestype'];
echo '<input type="hidden" name="SelectedCOGSPostingID" value="', $SelectedCOGSPostingID, '" />';
} //end of if $SelectedCOGSPostingID only do the else when a new record is being entered
$SQL = "SELECT areacode,
areadescription
FROM areas";
$Result = DB_query($SQL);
echo '<fieldset>
<legend>', _('Select criteria for COGS posting'), '</legend>
<field>
<label for="Area">', _('Area'), ':</label>
<select name="Area" autofocus="autofocus">
<option value="AN">', _('Any Other'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['Area']) and $MyRow['areacode'] == $_POST['Area']) {
echo '<option selected="selected" value="', $MyRow['areacode'], '">', $MyRow['areadescription'], '</option>';
} else {
echo '<option value="', $MyRow['areacode'], '">', $MyRow['areadescription'], '</option>';
}
} //end while loop
echo '</select>
<fieldhelp>', _('Select the area to be used in this group. To cover all areas just select Any Other'), '</fieldhelp>
</field>';
$SQL = "SELECT categoryid, categorydescription FROM stockcategory";
$Result = DB_query($SQL);
echo '<field>
<label for="StkCat">', _('Stock Category'), ':</label>
<select name="StkCat">
<option value="ANY">', _('Any Other'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['StkCat']) and $MyRow['categoryid'] == $_POST['StkCat']) {
echo '<option selected="selected" value="', $MyRow['categoryid'], '">', $MyRow['categorydescription'], '</option>';
} else {
echo '<option value="', $MyRow['categoryid'], '">', $MyRow['categorydescription'], '</option>';
}
} //end while loop
echo '</select>
<fieldhelp>', _('Select the stock category to be used in this group. To cover all categories just select Any Other'), '</fieldhelp>
</field>';
$SQL = "SELECT typeabbrev, sales_type FROM salestypes";
$Result = DB_query($SQL);
echo '<field>
<label for="SalesType">', _('Sales Type'), ' / ', _('Price List'), ':</label>
<select name="SalesType">
<option value="AN">', _('Any Other'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['SalesType']) and $MyRow['typeabbrev'] == $_POST['SalesType']) {
echo '<option selected="selected" value="', $MyRow['typeabbrev'], '">', $MyRow['sales_type'], '</option>';
} else {
echo '<option value="', $MyRow['typeabbrev'], '">', $MyRow['sales_type'], '</option>';
}
} //end while loop
echo '</select>
<fieldhelp>', _('Select the sales type to be used in this group. To cover all types just select Any Other'), '</fieldhelp>
</field>';
echo '<field>
<label for="GLCode">', _('Post to GL account'), ':</label>';
GLSelect(1, 'GLCode');
echo '<fieldhelp>', _('Select the general ledger code to do COGS postingst to where the above criteria have been met.'), '</fieldhelp>
</field>';
echo '</fieldset>';
echo '<div class="centre">
<input type="submit" name="submit" value="', _('Enter Information'), '" />
</div>
</form>';
include ('includes/footer.php');
?>