- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / PaymentTerms.php
blobf0b398e281c58f8d87dc4101cb923b113fd0d355
1 <?php
2 /* $Revision: 1.10 $ */
4 $PageSecurity = 10;
6 include('includes/session.inc');
8 $title = _('Payment Terms Maintenance');
10 include('includes/header.inc');
13 if (isset($_GET['SelectedTerms'])){
14 $SelectedTerms = $_GET['SelectedTerms'];
15 } elseif (isset($_POST['SelectedTerms'])){
16 $SelectedTerms = $_POST['SelectedTerms'];
19 if (isset($_POST['submit'])) {
21 //initialise no input errors assumed initially before we test
22 $InputError = 0;
24 /* actions to take once the user has clicked the submit button
25 ie the page has called itself with some user input */
27 //first off validate inputs are sensible
29 if (strlen($_POST['TermsIndicator']) > 2) {
30 $InputError = 1;
31 prnMsg(_('The payment terms name must be two characters or less long'),'error');
32 } elseif (!is_long((int) $_POST['DayNumber'])){
33 $InputError = 1;
34 prnMsg( _('The number of days or the day in the following month must be numeric') ,'error');
35 } elseif (strlen($_POST['Terms']) > 40) {
36 $InputError = 1;
37 prnMsg( _('The terms description must be forty characters or less long') ,'error');
38 } elseif ($_POST['DayNumber'] > 30 AND $_POST['DaysOrFoll']==1) {
39 $InputError = 1;
40 prnMsg( _('When the check box is not checked to indicate a day in the following month is the due date') . ', ' . _('the due date cannot be a day after the 30th') . '. ' . _('A number between 1 and 30 is expected') ,'error');
41 } elseif ($_POST['DayNumber']>360 AND $_POST['DaysOrFoll'] ==0) {
42 $InputError = 1;
43 prnMsg( _('When the check box is checked to indicate that the term expects a number of days after which accounts are due') . ', ' . _('the number entered should be less than 361 days') ,'error');
47 if (isset($SelectedTerms) AND $InputError !=1) {
49 /*SelectedTerms 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*/
51 if ($_POST['DaysOrFoll']=='on') {
52 $sql = "UPDATE paymentterms SET
53 terms='" . $_POST['Terms'] . "',
54 dayinfollowingmonth=0,
55 daysbeforedue=" . $_POST['DayNumber'] . "
56 WHERE termsindicator = '" . $SelectedTerms . "'";
57 } else {
58 $sql = "UPDATE paymentterms SET
59 terms='" . $_POST['Terms'] . "',
60 dayinfollowingmonth=" . $_POST['DayNumber'] . ",
61 daysbeforedue=0
62 WHERE termsindicator = '" . $SelectedTerms . "'";
65 $msg = _('The payment terms definition record has been updated') . '.';
66 } else if ($InputError !=1) {
68 /*Selected terms is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new payment terms form */
70 if ($_POST['DaysOrFoll']=='on') {
71 $sql = "INSERT INTO paymentterms (termsindicator,
72 terms,
73 daysbeforedue,
74 dayinfollowingmonth)
75 VALUES (
76 '" . $_POST['TermsIndicator'] . "',
77 '" . $_POST['Terms'] . "',
78 " . $_POST['DayNumber'] . ",
80 )";
81 } else {
82 $sql = "INSERT INTO paymentterms (termsindicator,
83 terms,
84 daysbeforedue,
85 dayinfollowingmonth)
86 VALUES (
87 '" . $_POST['TermsIndicator'] . "',
88 '" . $_POST['Terms'] . "',
90 " . $_POST['DayNumber'] . "
91 )";
94 $msg = _('The payment terms definition record has been added') . '.';
96 if ($InputError !=1){
97 //run the SQL from either of the above possibilites
98 $result = DB_query($sql,$db);
99 prnMsg($msg,'success');
100 unset($SelectedTerms);
101 unset($_POST['DaysOrFoll']);
102 unset($_POST['TermsIndicator']);
103 unset($_POST['Terms']);
104 unset($_POST['DayNumber']);
107 } elseif (isset($_GET['delete'])) {
108 //the link to delete a selected record was clicked instead of the submit button
110 // PREVENT DELETES IF DEPENDENT RECORDS IN DebtorsMaster
112 $sql= "SELECT COUNT(*) FROM debtorsmaster WHERE debtorsmaster.paymentterms = '$SelectedTerms'";
113 $result = DB_query($sql,$db);
114 $myrow = DB_fetch_row($result);
115 if ($myrow[0] > 0) {
116 prnMsg( _('Cannot delete this payment term because customer accounts have been created referring to this term'),'warn');
117 echo '<br> ' . _('There are') . ' ' . $myrow[0] . ' ' . _('customer accounts that refer to this payment term');
118 } else {
119 $sql= "SELECT COUNT(*) FROM suppliers WHERE suppliers.paymentterms = '$SelectedTerms'";
120 $result = DB_query($sql,$db);
121 $myrow = DB_fetch_row($result);
122 if ($myrow[0] > 0) {
123 prnMsg( _('Cannot delete this payment term because supplier accounts have been created referring to this term'),'warn');
124 echo '<br> ' . _('There are') . ' ' . $myrow[0] . ' ' . _('supplier accounts that refer to this payment term');
125 } else {
126 //only delete if used in neither customer or supplier accounts
128 $sql="DELETE FROM paymentterms WHERE termsindicator='$SelectedTerms'";
129 $result = DB_query($sql,$db);
130 prnMsg( _('The payment term definition record has been deleted') . '!','success');
133 //end if payment terms used in customer or supplier accounts
137 if (!isset($SelectedTerms)) {
139 /* It could still be the second time the page has been run and a record has been selected for modification - SelectedTerms will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters
140 then none of the above are true and the list of payment termss will be displayed with
141 links to delete or edit each. These will call the same page again and allow update/input
142 or deletion of the records*/
144 $sql = 'SELECT termsindicator, terms, daysbeforedue, dayinfollowingmonth FROM paymentterms';
145 $result = DB_query($sql, $db);
147 echo '<CENTER><table border=1>';
148 echo '<tr><td class="tableheader">' . _('Term Code') . '</td>
149 <td class="tableheader">' . _('Description') . '</td>
150 <td class="tableheader">' . _('Following Month On') . '</td>
151 <td class="tableheader">' . _('Due After (Days)') . '</td>
152 </tr>';
154 while ($myrow=DB_fetch_row($result)) {
156 if ($myrow[3]==0) {
157 $FollMthText = _('N/A');
158 } else {
159 $FollMthText = $myrow[3] . _('th');
162 if ($myrow[2]==0) {
163 $DueAfterText = _('N/A');
164 } else {
165 $DueAfterText = $myrow[2] . ' ' . _('days');
168 printf("<tr><td>%s</td>
169 <td>%s</td>
170 <td>%s</td>
171 <td>%s</td>
172 <td><a href=\"%s&SelectedTerms=%s\">" . _('Edit') . "</a></td>
173 <td><a href=\"%s&SelectedTerms=%s&delete=1\">" . _('Delete') . "</a></td>
174 </tr>",
175 $myrow[0],
176 $myrow[1],
177 $FollMthText,
178 $DueAfterText,
179 $_SERVER['PHP_SELF'] . '?' . SID,
180 $myrow[0],
181 $_SERVER['PHP_SELF']. '?' . SID,
182 $myrow[0]);
184 } //END WHILE LIST LOOP
185 echo '</TABLE></CENTER><P>';
186 } //end of ifs and buts!
188 if (isset($SelectedTerms)) {
189 echo '<CENTER><A HREF="' . $_SERVER['PHP_SELF'] . '?' . SID .'">' . _('Show all Payment Terms Definitions') . '</a></Center>';
192 if (!isset($_GET['delete'])) {
194 echo '<FORM METHOD="post" action=' . $_SERVER['PHP_SELF'] . '?' . SID . '>';
196 if (isset($SelectedTerms)) {
197 //editing an existing payment terms
199 $sql = "SELECT termsindicator,
200 terms,
201 daysbeforedue,
202 dayinfollowingmonth
203 FROM paymentterms
204 WHERE termsindicator='$SelectedTerms'";
206 $result = DB_query($sql, $db);
207 $myrow = DB_fetch_array($result);
209 $_POST['TermsIndicator'] = $myrow['termsindicator'];
210 $_POST['Terms'] = $myrow['terms'];
211 $DaysBeforeDue = $myrow['daysbeforedue'];
212 $DayInFollowingMonth = $myrow['dayinfollowingmonth'];
214 echo '<INPUT TYPE=HIDDEN NAME="SelectedTerms" VALUE="' . $SelectedTerms . '">';
215 echo '<INPUT TYPE=HIDDEN NAME="TermsIndicator" VALUE="' . $_POST['TermsIndicator'] . '">';
216 echo '<CENTER><TABLE><TR><TD>' . _('Term Code') . ':</TD><TD>';
217 echo $_POST['TermsIndicator'] . '</TD></TR>';
219 } else { //end of if $SelectedTerms only do the else when a new record is being entered
221 if (!isset($_POST['TermsIndicator'])) $_POST['TermsIndicator']='';
222 if (!isset($DaysBeforeDue)) $DaysBeforeDue=0;
223 //if (!isset($DayInFollowingMonth)) $DayInFollowingMonth=0;
224 unset($DayInFollowingMonth); // Rather unset for a new record
225 if (!isset($_POST['Terms'])) $_POST['Terms']='';
227 echo '<CENTER><TABLE><TR><TD>' . _('Term Code') . ':</TD><TD><input type="Text" name="TermsIndicator" value="' . $_POST['TermsIndicator'] . '" SIZE=3 MAXLENGTH=2></TD></TR>';
234 <TR><TD><?php echo _('Terms Description'); ?>:</TD>
235 <TD>
236 <INPUT TYPE="text" name="Terms" VALUE="<?php echo $_POST['Terms'];?>" SIZE=35 MAXLENGTH=40>
237 </TD></TR>
238 <TR><TD><?php echo _('Due After A Given No. Of Days'); ?>:</TD>
239 <TD><INPUT TYPE="checkbox" name="DaysOrFoll" <?php if ( isset($DayInFollowingMonth) && !$DayInFollowingMonth) { echo "checked"; }?> >
240 </TD></TR>
241 <TR><TD><?php echo _('Days (Or Day In Following Month)'); ?>:</TD>
242 <TD>
243 <INPUT TYPE="Text" name="DayNumber" SIZE=4 MAXLENGTH=3 VALUE=
244 <?php if ($DaysBeforeDue !=0) {
245 echo $DaysBeforeDue;
246 } else {
247 echo $DayInFollowingMonth;
248 } ?>>
249 </TD></TR>
251 </TABLE>
253 <CENTER><input type="Submit" name="submit" value="<?php echo _('Enter Information'); ?>">
255 </FORM>
257 <?php
258 } //end if record deleted no point displaying form to add record
260 include('includes/footer.inc');