summaryrefslogtreecommitdiff
path: root/bin/lynx/pe.pl
blob: daf26fc41c3ca6728c1dcce3fc9bdad973902787 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # Copyright (C) 2006
  4. # This work contains copyrighted information from a number of sources all used
  5. # with permission.
  6. #
  7. # This file contains source code included with or based on SQL-Ledger which
  8. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  9. # under the GNU General Public License version 2 or, at your option, any later
  10. # version. For a full list including contact information of contributors,
  11. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  12. #
  13. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  14. # Copyright (c) 2002
  15. #
  16. # Author: DWS Systems Inc.
  17. # Web: http://www.sql-ledger.org
  18. #
  19. #
  20. #
  21. # Author: DWS Systems Inc.
  22. # Web: http://sourceforge.net/projects/ledger-smb/
  23. #
  24. #
  25. # This program is free software; you can redistribute it and/or modify
  26. # it under the terms of the GNU General Public License as published by
  27. # the Free Software Foundation; either version 2 of the License, or
  28. # (at your option) any later version.
  29. #
  30. # This program is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. # GNU General Public License for more details.
  34. # You should have received a copy of the GNU General Public License
  35. # along with this program; if not, write to the Free Software
  36. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  37. #======================================================================
  38. #
  39. # project/job administration
  40. # partsgroup administration
  41. # translation maintainance
  42. #
  43. #======================================================================
  44. use SL::PE;
  45. use SL::AA;
  46. use SL::OE;
  47. 1;
  48. # end of main
  49. sub add {
  50. # construct callback
  51. $form->{callback} = "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
  52. &{ "prepare_$form->{type}" };
  53. $form->{orphaned} = 1;
  54. &display_form;
  55. }
  56. sub edit {
  57. &{ "prepare_$form->{type}" };
  58. &display_form;
  59. }
  60. sub prepare_partsgroup { PE->get_partsgroup(\%myconfig, \%$form) if $form->{id} }
  61. sub prepare_pricegroup { PE->get_pricegroup(\%myconfig, \%$form) if $form->{id} }
  62. sub prepare_job {
  63. # $locale->text('Add Job')
  64. # $locale->text('Edit Job')
  65. $form->{vc} = 'customer';
  66. PE->get_job(\%myconfig, \%$form);
  67. $form->{taxaccounts} = "";
  68. for (keys %{ $form->{IC_links} }) {
  69. $form->{"select$_"} = "";
  70. foreach $ref (@{ $form->{IC_links}{$_} }) {
  71. if (/IC_tax/) {
  72. if (/taxpart/) {
  73. $form->{taxaccounts} .= "$ref->{accno} ";
  74. $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
  75. if ($form->{id}) {
  76. if ($form->{amount}{$ref->{accno}}) {
  77. $form->{"IC_tax_$ref->{accno}"} = "checked";
  78. }
  79. } else {
  80. $form->{"IC_tax_$ref->{accno}"} = "checked";
  81. }
  82. }
  83. } else {
  84. $form->{"select$_"} .= "<option>$ref->{accno}--$ref->{description}\n";
  85. }
  86. }
  87. }
  88. chop $form->{taxaccounts};
  89. $form->{selectIC_income} = $form->{selectIC_sale};
  90. $form->{IC_income} = $form->{IC_sale};
  91. $form->{IC_income} = qq|$form->{income_accno}--$form->{income_description}|;
  92. delete $form->{IC_links};
  93. $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  94. if (@{ $form->{"all_$form->{vc}"} }) {
  95. $form->{"$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  96. $form->{"select$form->{vc}"} = qq|<option>\n|;
  97. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  98. }
  99. $form->get_partsgroup(\%myconfig, {all => 1});
  100. $form->{partsgroup} = $form->quote($form->{partsgroup})."--$form->{partsgroup_id}";
  101. if (@{ $form->{all_partsgroup} }) {
  102. $form->{selectpartsgroup} = qq|<option>\n|;
  103. for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|<option value="|.$form->quote($_->{partsgroup}).qq|--$_->{id}">$_->{partsgroup}\n| }
  104. }
  105. $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
  106. $form->{readonly} = 1 if $myconfig{acs} =~ /Job Costing--Add Job/;
  107. }
  108. sub job_header {
  109. for (qw(partnumber partdescription description notes unit)) { $form->{$_} = $form->quote($form->{$_}) }
  110. for (qw(production weight)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
  111. for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
  112. if (($rows = $form->numtextrows($form->{partdescription}, 60)) > 1) {
  113. $partdescription = qq|<textarea name="partdescription" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{partdescription}</textarea>|;
  114. } else {
  115. $partdescription = qq|<input name=partdescription size=60 value="$form->{partdescription}">|;
  116. }
  117. if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
  118. $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
  119. } else {
  120. $description = qq|<input name=description size=60 value="$form->{description}">|;
  121. }
  122. if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
  123. $rows = 2;
  124. }
  125. $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
  126. $form->{selectIC_income} = $form->unescape($form->{selectIC_income});
  127. $form->{"select$form->{vc}"} = $form->unescape($form->{"select$form->{vc}"});
  128. $form->{"select$form->{vc}"} =~ s/ selected//;
  129. $form->{"select$form->{vc}"} =~ s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
  130. $label = ucfirst $form->{vc};
  131. if ($form->{"select$form->{vc}"}) {
  132. $name = qq|
  133. <tr>
  134. <th align=right nowrap>|.$locale->text($label).qq|</th>
  135. <td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td>
  136. <input type=hidden name="select$form->{vc}" value="|.
  137. $form->escape($form->{"select$form->{vc}"},1).qq|">
  138. </tr>
  139. |;
  140. } else {
  141. $name = qq|
  142. <tr>
  143. <th align=right nowrap>|.$locale->text($label).qq|</th>
  144. <td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td>
  145. <input type=hidden name="select$form->{vc}" value="|.
  146. $form->escape($form->{"select$form->{vc}"},1).qq|">
  147. </tr>
  148. |;
  149. }
  150. if ($form->{orphaned}) {
  151. for (qw(income)) {
  152. $form->{"selectIC_$_"} =~ s/ selected//;
  153. $form->{"selectIC_$_"} =~ s/option>\Q$form->{"IC_$_"}\E/option selected>$form->{"IC_$_"}/;
  154. }
  155. $production = qq|
  156. <tr>
  157. <th align=right nowrap>|.$locale->text('Production').qq|</th>
  158. <td><input name=production size=10 value="$form->{production}"></td>
  159. <th align=right nowrap>|.$locale->text('Completed').qq|</th>
  160. <td>$form->{completed}</td>
  161. </tr>
  162. |;
  163. } else {
  164. $form->{selectIC_income} = qq|<option selected>$form->{IC_income}|;
  165. $production = qq|
  166. <tr>
  167. <th align=right nowrap>|.$locale->text('Production').qq|</th>
  168. <td><input type=hidden name=production value="$form->{production}">$form->{production}</td>
  169. <th align=right nowrap>|.$locale->text('Completed').qq|</th>
  170. <td>$form->{completed}</td>
  171. </tr>
  172. |;
  173. }
  174. for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" }
  175. if ($form->{selectpartsgroup}) {
  176. $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
  177. $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|;
  178. $form->{partsgroup} = $form->quote($form->{partsgroup});
  179. $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
  180. $partsgroup .= qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
  181. $group = $locale->text('Group');
  182. }
  183. $linkaccounts = qq|
  184. <tr>
  185. <th align=right nowrap>|.$locale->text('Income').qq|</th>
  186. <td><select name=IC_income>$form->{selectIC_income}</select></td>
  187. </tr>
  188. |;
  189. for (split / /, $form->{taxaccounts}) {
  190. $tax .= qq|
  191. <input class=checkbox type=checkbox name="IC_tax_$_" value=1 $form->{"IC_tax_$_"}>&nbsp;<b>$form->{"IC_tax_${_}_description"}</b>
  192. <br><input type=hidden name=IC_tax_${_}_description value="$form->{"IC_tax_${_}_description"}">
  193. |;
  194. }
  195. if ($tax) {
  196. $linkaccounts .= qq|
  197. <tr>
  198. <th align=right>|.$locale->text('Tax').qq|</th>
  199. <td>$tax</td>
  200. </tr>
  201. |;
  202. }
  203. $partnumber = qq|
  204. <tr>
  205. <td>
  206. <table>
  207. <tr valign=top>
  208. <th align=left>|.$locale->text('Number').qq|</th>
  209. <th align=left>|.$locale->text('Description').qq|</th>
  210. <th align=left>$group</th>
  211. </tr>
  212. <tr valign=top>
  213. <td><input name=partnumber value="$form->{partnumber}" size=20></td>
  214. <td>$partdescription</td>
  215. <td>$partsgroup</td>
  216. </tr>
  217. </table>
  218. </td>
  219. </tr>
  220. |;
  221. $form->{title} = ($form->{id}) ? $locale->text('Edit Job') : $locale->text('Add Job');
  222. $form->header;
  223. print qq|
  224. <body>
  225. <form method=post action=$form->{script}>
  226. |;
  227. for (qw(partnumber startdate enddate)) { $form->{"old$_"} = $form->{$_} }
  228. print qq|<input type=hidden name="selectIC_income" value="|.$form->escape($form->{"selectIC_income"},1).qq|">\n|;
  229. $form->hide_form("id", "type", "old$form->{vc}", "$form->{vc}_id", "orphaned", "taxaccounts", "vc", "project");
  230. print qq|
  231. <table width=100%>
  232. <tr>
  233. <th class=listtop>$form->{title}</th>
  234. </tr>
  235. <tr height="5"></tr>
  236. <tr>
  237. <td>
  238. <table>
  239. <tr>
  240. <th align=right>|.$locale->text('Number').qq|</th>
  241. <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
  242. <th align=right>|.$locale->text('Description').qq|</th>
  243. <td>$description</td>
  244. </tr>
  245. $name
  246. <tr>
  247. <th align=right>|.$locale->text('Startdate').qq|</th>
  248. <td><input name=startdate size=11 title="($myconfig{dateformat})" value=$form->{startdate}></td>
  249. <th align=right>|.$locale->text('Enddate').qq|</th>
  250. <td><input name=enddate size=11 title="($myconfig{dateformat})" value=$form->{enddate}></td>
  251. </tr>
  252. $production
  253. </table>
  254. </td>
  255. </tr>
  256. <tr class="listheading">
  257. <th class="listheading" align="center">|.$locale->text('Assembly').qq|</th>
  258. </tr>
  259. <tr>
  260. <td>
  261. <table width=100%>
  262. $partnumber
  263. <tr>
  264. <td colspan=3>
  265. <table width=100%>
  266. <tr>
  267. <td width=70%>
  268. <table width=100%>
  269. <tr class="listheading">
  270. <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
  271. </tr>
  272. $linkaccounts
  273. <tr>
  274. <th align="left">|.$locale->text('Notes').qq|</th>
  275. </tr>
  276. <tr>
  277. <td colspan=2>
  278. $notes
  279. </td>
  280. </tr>
  281. </table>
  282. </td>
  283. <td align=right>
  284. <table>
  285. <tr>
  286. <th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
  287. <td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>
  288. </tr>
  289. <tr>
  290. <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
  291. <td><input name=listprice size=11 value=$form->{listprice}></td>
  292. </tr>
  293. <tr>
  294. <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
  295. <td><input name=sellprice size=11 value=$form->{sellprice}></td>
  296. </tr>
  297. <tr>
  298. <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
  299. <td>
  300. <table>
  301. <tr>
  302. <td>
  303. <input name=weight size=10 value=$form->{weight}>
  304. </td>
  305. <th>
  306. &nbsp;
  307. $form->{weightunit}
  308. <input type=hidden name=weightunit value=$form->{weightunit}>
  309. </th>
  310. </tr>
  311. </table>
  312. </td>
  313. <tr>
  314. <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
  315. <td><input name=bin size=10 value="$form->{bin}"></td>
  316. </tr>
  317. <tr>
  318. <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
  319. <td><input name=unit size=5 value="$form->{unit}"></td>
  320. </tr>
  321. </table>
  322. </td>
  323. </tr>
  324. </table>
  325. </td>
  326. </tr>
  327. </table>
  328. </td>
  329. </tr>
  330. <tr>
  331. <td><hr size=3 noshade></td>
  332. </tr>
  333. </table>
  334. |;
  335. }
  336. sub job_footer {
  337. $form->hide_form(qw(callback path login sessionid));
  338. # type=submit $locale->text('Update')
  339. # type=submit $locale->text('Save')
  340. # type=submit $locale->text('Delete')
  341. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  342. );
  343. if ($myconfig{acs} !~ /Job Costing--Add Job/) {
  344. $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  345. if ($form->{id} && $form->{orphaned}) {
  346. $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
  347. }
  348. }
  349. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  350. if ($form->{menubar}) {
  351. require "$form->{path}/menu.pl";
  352. &menubar;
  353. }
  354. print qq|
  355. </form>
  356. </body>
  357. </html>
  358. |;
  359. }
  360. sub list_stock {
  361. PE->list_stock(\%myconfig, \%$form);
  362. $form->{title} = $locale->text('Stock Finished Goods');
  363. $form->{action} = "list_stock";
  364. $href = "$form->{script}?";
  365. for (qw(action direction oldsort type path login sessionid status)) { $href .= "$_=$form->{$_}&" }
  366. $form->sort_order();
  367. $callback = "$form->{script}?";
  368. for (qw(action direction oldsort type path login sessionid status)) { $callback .= "$_=$form->{$_}&" }
  369. @column_index = $form->sort_columns(qw(projectnumber description startdate partnumber production completed stock));
  370. if ($form->{projectnumber}) {
  371. $href .= "&projectnumber=".$form->escape($form->{projectnumber});
  372. $callback .= "&projectnumber=$form->{projectnumber}";
  373. ($var) = split /--/, $form->{projectnumber};
  374. $option .= "\n<br>".$locale->text('Job Number')." : $var";
  375. }
  376. if ($form->{stockingdate}) {
  377. $href .= "&stockingdate=$form->{stockingdate}";
  378. $option .= "\n<br>".$locale->text('As of')." : ".$locale->date(\%myconfig, $form->{stockingdate}, 1);
  379. }
  380. $column_header{projectnumber} = qq|<th width=30%><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
  381. $column_header{description} = qq|<th width=50%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  382. $column_header{startdate} = qq|<th width=10%><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
  383. $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Assembly') . "</a></th>";
  384. $column_header{production} = "<th class=listheading>" . $locale->text('Production') . "</a></th>";
  385. $column_header{completed} = "<th class=listheading>" . $locale->text('Completed') . "</a></th>";
  386. $column_header{stock} = "<th class=listheading>" . $locale->text('Add') . "</a></th>";
  387. $form->header;
  388. if (@{ $form->{all_project} }) {
  389. $sameitem = $form->{all_project}->[0]->{$form->{sort}};
  390. }
  391. print qq|
  392. <body>
  393. <form method=post action=$form->{script}>
  394. <table width=100%>
  395. <tr>
  396. <th class=listtop>$form->{title}</th>
  397. </tr>
  398. <tr height="5"></tr>
  399. <tr>
  400. <td>$option</td>
  401. </tr>
  402. <tr>
  403. <td>
  404. <table width=100%>
  405. <tr class=listheading>
  406. |;
  407. for (@column_index) { print "$column_header{$_}\n" }
  408. print qq|
  409. </tr>
  410. |;
  411. # escape callback
  412. $form->{callback} = $callback .= "&sort=$form->{sort}";
  413. # escape callback for href
  414. $callback = $form->escape($callback);
  415. # flip direction
  416. $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
  417. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  418. $i = 0;
  419. foreach $ref (@{ $form->{all_project} }) {
  420. $i++;
  421. for (qw(projectnumber description startdate enddate partnumber)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  422. for (qw(production completed)) { $column_data{$_} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{$_}).qq|</td>| }
  423. $column_data{stock} = qq|<td><input name="stock_$i" size=6></td>|;
  424. $j++; $j %= 2;
  425. print qq|
  426. <tr valign=top class=listrow$j>
  427. <input type=hidden name="id_$i" value=$ref->{id}>
  428. |;
  429. for (@column_index) { print "$column_data{$_}\n" }
  430. print "
  431. </tr>
  432. ";
  433. }
  434. print qq|
  435. </table>
  436. </td>
  437. </tr>
  438. <tr>
  439. <td><hr size=3 noshade></td>
  440. </tr>
  441. </table>
  442. |;
  443. $form->hide_form(qw(callback type path login sessionid status));
  444. print qq|
  445. <input type=hidden name=nextsub value="stock">
  446. <br>
  447. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  448. </form>
  449. </body>
  450. </html>
  451. |;
  452. }
  453. sub stock {
  454. if (PE->stock_assembly(\%myconfig, \%$form)) {
  455. $form->redirect($locale->text('Assembly stocked!'));
  456. } else {
  457. $form->error($locale->text('Cannot stock Assembly!'));
  458. }
  459. }
  460. sub prepare_project {
  461. $form->{vc} = 'customer';
  462. PE->get_project(\%myconfig, \%$form);
  463. $form->{title} = ($form->{id}) ? $locale->text('Edit Project') : $locale->text('Add Project');
  464. $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  465. if (@{ $form->{"all_$form->{vc}"} }) {
  466. $form->{"$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  467. $form->{"select$form->{vc}"} = qq|<option>\n|;
  468. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  469. }
  470. }
  471. sub search {
  472. # accounting years
  473. $form->all_years(\%myconfig);
  474. if (@{ $form->{all_years} }) {
  475. $form->{selectaccountingyear} = "<option>\n";
  476. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  477. $form->{selectaccountingmonth} = "<option>\n";
  478. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  479. $fromto = qq|
  480. <tr>
  481. <th align=right>|.$locale->text('Startdate').qq|</th>
  482. <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 title="($myconfig{'dateformat'})">|.$locale->text('To').qq|
  483. <input name=startdateto size=11 title="($myconfig{'dateformat'})"></td>
  484. </tr>
  485. |;
  486. $selectperiod = qq|
  487. <tr>
  488. <th align=right>|.$locale->text('Period').qq|</th>
  489. <td colspan=3>
  490. <select name=month>$form->{selectaccountingmonth}</select>
  491. <select name=year>$form->{selectaccountingyear}</select>
  492. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  493. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  494. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  495. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  496. </td>
  497. </tr>
  498. |;
  499. }
  500. $orphaned = qq|
  501. <input name=status class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned');
  502. if ($form->{type} eq 'project') {
  503. $report = "project_report";
  504. $sort = "projectnumber";
  505. $form->{title} = $locale->text('Projects');
  506. $number = qq|
  507. <tr>
  508. <th align=right width=1%>|.$locale->text('Number').qq|</th>
  509. <td><input name=projectnumber size=20></td>
  510. </tr>
  511. <tr>
  512. <th align=right>|.$locale->text('Description').qq|</th>
  513. <td><input name=description size=60></td>
  514. </tr>
  515. |;
  516. }
  517. if ($form->{type} eq 'stock') {
  518. $report = "list_stock";
  519. $form->{title} = $locale->text('Stock Finished Goods');
  520. PE->list_stock(\%myconfig, \%$form);
  521. $selectperiod = "";
  522. $orphaned = "";
  523. $fromto = qq|
  524. <tr>
  525. <th align=right nowrap>|.$locale->text('As of').qq|</th>
  526. <td><input name=stockingdate size=11 title="$myconfig{dateformat}"></td>
  527. </tr>
  528. |;
  529. $number = qq|
  530. <tr>
  531. <th align=right width=1%>|.$locale->text('Job Number').qq|</th>
  532. <td><input name=projectnumber size=20></td>
  533. </tr>
  534. <tr>
  535. <th align=right>|.$locale->text('Description').qq|</th>
  536. <td><input name=description size=60></td>
  537. </tr>
  538. |;
  539. }
  540. if ($form->{type} eq 'job') {
  541. $report = "job_report";
  542. $sort = "projectnumber";
  543. $form->{title} = $locale->text('Jobs');
  544. $number = qq|
  545. <tr>
  546. <th align=right width=1%>|.$locale->text('Number').qq|</th>
  547. <td><input name=projectnumber size=20></td>
  548. </tr>
  549. <tr>
  550. <th align=right>|.$locale->text('Description').qq|</th>
  551. <td><input name=description size=60></td>
  552. </tr>
  553. |;
  554. }
  555. if ($form->{type} eq 'partsgroup') {
  556. $report = "partsgroup_report";
  557. $sort = 'partsgroup';
  558. $form->{title} = $locale->text('Groups');
  559. $fromto = "";
  560. $selectperiod = "";
  561. $number = qq|
  562. <tr>
  563. <th align=right width=1%>|.$locale->text('Group').qq|</th>
  564. <td><input name=partsgroup size=20></td>
  565. </tr>
  566. |;
  567. }
  568. if ($form->{type} eq 'pricegroup') {
  569. $report = "pricegroup_report";
  570. $sort = 'pricegroup';
  571. $form->{title} = $locale->text('Pricegroups');
  572. $fromto = "";
  573. $selectperiod = "";
  574. $number = qq|
  575. <tr>
  576. <th align=right width=1%>|.$locale->text('Pricegroup').qq|</th>
  577. <td><input name=pricegroup size=20></td>
  578. </tr>
  579. |;
  580. }
  581. $form->header;
  582. print qq|
  583. <body>
  584. <form method=post action=$form->{script}>
  585. <input type=hidden name=sort value=$sort>
  586. <input type=hidden name=type value=$form->{type}>
  587. <table width=100%>
  588. <tr>
  589. <th class=listtop>$form->{title}</th>
  590. </tr>
  591. <tr height="5"></tr>
  592. <tr>
  593. <td>
  594. <table width=100%>
  595. $number
  596. $fromto
  597. $selectperiod
  598. <tr>
  599. <td></td>
  600. <td><input name=status class=radio type=radio value=all checked>&nbsp;|.$locale->text('All').qq|
  601. <input name=status class=radio type=radio value=active>&nbsp;|.$locale->text('Active').qq|
  602. <input name=status class=radio type=radio value=inactive>&nbsp;|.$locale->text('Inactive').qq|
  603. $orphaned</td>
  604. </tr>
  605. </table>
  606. </td>
  607. </tr>
  608. <tr>
  609. <td><hr size=3 noshade></td>
  610. </tr>
  611. </table>
  612. <input type=hidden name=nextsub value=$report>
  613. |;
  614. $form->hide_form(qw(path login sessionid title));
  615. print qq|
  616. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  617. </form>
  618. |;
  619. if ($form->{menubar}) {
  620. require "$form->{path}/menu.pl";
  621. &menubar;
  622. }
  623. print qq|
  624. </body>
  625. </html>
  626. |;
  627. }
  628. sub job_report {
  629. for (qw(projectnumber description)) { $form->{$_} = $form->unescape($form->{$_}) }
  630. PE->jobs(\%myconfig, \%$form);
  631. $form->{action} = "job_report";
  632. &list_projects;
  633. }
  634. sub project_report {
  635. for (qw(projectnumber description)) { $form->{$_} = $form->unescape($form->{$_}) }
  636. PE->projects(\%myconfig, \%$form);
  637. $form->{action} = "project_report";
  638. &list_projects;
  639. }
  640. sub list_projects {
  641. $href = "$form->{script}?";
  642. for (qw(action direction oldsort type path login sessionid status startdatefrom startdateto)) { $href .= "$_=$form->{$_}&" }
  643. $form->sort_order();
  644. $callback = "$form->{script}?";
  645. for (qw(action direction oldsort type path login sessionid status startdatefrom startdateto)) { $callback .= "$_=$form->{$_}&" }
  646. @column_index = $form->sort_columns(qw(projectnumber description name startdate enddate));
  647. if ($form->{status} eq 'all') {
  648. $option = $locale->text('All');
  649. }
  650. if ($form->{status} eq 'orphaned') {
  651. $option .= $locale->text('Orphaned');
  652. }
  653. if ($form->{status} eq 'active') {
  654. $option = $locale->text('Active');
  655. @column_index = $form->sort_columns(qw(projectnumber description name startdate));
  656. }
  657. if ($form->{status} eq 'inactive') {
  658. $option = $locale->text('Inactive');
  659. }
  660. if ($form->{type} eq 'project') {
  661. $label = $locale->text('Project');
  662. $form->{title} = $locale->text('Projects');
  663. } else {
  664. $label = $locale->text('Job');
  665. push @column_index, qw(partnumber production completed);
  666. $form->{title} = $locale->text('Jobs');
  667. }
  668. if ($form->{projectnumber}) {
  669. $href .= "&projectnumber=".$form->escape($form->{projectnumber});
  670. $callback .= "&projectnumber=$form->{projectnumber}";
  671. $option .= "\n<br>$label : $form->{projectnumber}";
  672. }
  673. if ($form->{description}) {
  674. $href .= "&description=".$form->escape($form->{description});
  675. $callback .= "&description=$form->{description}";
  676. $option .= "\n<br>".$locale->text('Description')." : $form->{description}";
  677. }
  678. if ($form->{startdatefrom}) {
  679. $href .= "&startdatefrom=$form->{startdatefrom}";
  680. $option .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{startdatefrom}, 1);
  681. }
  682. if ($form->{startdateto}) {
  683. $href .= "&startdateto=$form->{startdateto}";
  684. if ($form->{startdatefrom}) {
  685. $option .= " ";
  686. } else {
  687. $option .= "\n<br>" if ($option);
  688. }
  689. $option .= $locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{startdateto}, 1);
  690. }
  691. $column_header{projectnumber} = qq|<th><a class=listheading href=$href&sort=projectnumber>|.$locale->text('Number').qq|</a></th>|;
  692. $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  693. $column_header{startdate} = qq|<th width=10><a class=listheading href=$href&sort=startdate>|.$locale->text('Startdate').qq|</a></th>|;
  694. $column_header{enddate} = qq|<th width=10><a class=listheading href=$href&sort=enddate>|.$locale->text('Enddate').qq|</a></th>|;
  695. $column_header{partnumber} = "<th><a class=listheading href=$href&sort=partnumber>" . $locale->text('Assembly') . "</a></th>";
  696. $column_header{production} = "<th width=10 class=listheading>" . $locale->text('Production') . "</th>";
  697. $column_header{completed} = "<th width=10 class=listheading>" . $locale->text('Completed') . "</th>";
  698. $column_header{name} = "<th class=listheading>" . $locale->text('Customer') . "</th>";
  699. $form->header;
  700. if (@{ $form->{all_project} }) {
  701. $sameitem = $form->{all_project}->[0]->{$form->{sort}};
  702. }
  703. print qq|
  704. <body>
  705. <table width=100%>
  706. <tr>
  707. <th class=listtop>$form->{title}</th>
  708. </tr>
  709. <tr height="5"></tr>
  710. <tr>
  711. <td>$option</td>
  712. </tr>
  713. <tr>
  714. <td>
  715. <table width=100%>
  716. <tr class=listheading>
  717. |;
  718. for (@column_index) { print "$column_header{$_}\n" }
  719. print qq|
  720. </tr>
  721. |;
  722. # escape callback
  723. $form->{callback} = $callback .= "&sort=$form->{sort}";
  724. # escape callback for href
  725. $callback = $form->escape($callback);
  726. # flip direction
  727. $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
  728. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  729. foreach $ref (@{ $form->{all_project} }) {
  730. for (qw(description startdate enddate name)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  731. for (qw(production completed)) { $column_data{$_} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{$_}) }
  732. $column_data{projectnumber} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{projectnumber}</td>|;
  733. $column_data{partnumber} = qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
  734. $j++; $j %= 2;
  735. print qq|
  736. <tr valign=top class=listrow$j>
  737. |;
  738. for (@column_index) { print "$column_data{$_}\n" }
  739. print "
  740. </tr>
  741. ";
  742. }
  743. $i = 1;
  744. if ($form->{type} eq 'project') {
  745. if ($myconfig{acs} !~ /Projects--Projects/) {
  746. $button{'Projects--Add Project'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Project').qq|"> |;
  747. $button{'Projects--Add Project'}{order} = $i++;
  748. for (split /;/, $myconfig{acs}) {
  749. delete $button{$_};
  750. }
  751. }
  752. } else {
  753. if ($myconfig{acs} !~ /Job Costing--Job Costing/) {
  754. $button{'Job Costing--Add Job'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Job').qq|"> |;
  755. $button{'Job Costing--Add Job'}{order} = $i++;
  756. for (split /;/, $myconfig{acs}) {
  757. delete $button{$_};
  758. }
  759. }
  760. }
  761. print qq|
  762. </table>
  763. </td>
  764. </tr>
  765. <tr>
  766. <td><hr size=3 noshade></td>
  767. </tr>
  768. </table>
  769. <br>
  770. <form method=post action=$form->{script}>
  771. |;
  772. $form->hide_form(qw(callback type path login sessionid));
  773. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  774. print $item->{code};
  775. }
  776. if ($form->{menubar}) {
  777. require "$form->{path}/menu.pl";
  778. &menubar;
  779. }
  780. print qq|
  781. </form>
  782. </body>
  783. </html>
  784. |;
  785. }
  786. sub project_header {
  787. $form->{description} = $form->quote($form->{description});
  788. if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
  789. $description = qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
  790. } else {
  791. $description = qq|<input name=description size=60 value="$form->{description}">|;
  792. }
  793. $form->{"select$form->{vc}"} = $form->unescape($form->{"select$form->{vc}"});
  794. $form->{"select$form->{vc}"} =~ s/ selected//;
  795. $form->{"select$form->{vc}"} =~ s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
  796. $label = ucfirst $form->{vc};
  797. if ($form->{"select$form->{vc}"}) {
  798. $name = qq|
  799. <tr>
  800. <th align=right nowrap>|.$locale->text($label).qq|</th>
  801. <td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td>
  802. <input type=hidden name="select$form->{vc}" value="|.
  803. $form->escape($form->{"select$form->{vc}"},1).qq|">
  804. </tr>
  805. |;
  806. } else {
  807. $name = qq|
  808. <tr>
  809. <th align=right nowrap>|.$locale->text($label).qq|</th>
  810. <td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td>
  811. <input type=hidden name="select$form->{vc}" value="|.
  812. $form->escape($form->{"select$form->{vc}"},1).qq|">
  813. </tr>
  814. |;
  815. }
  816. $form->header;
  817. print qq|
  818. <body>
  819. <form method=post action=$form->{script}>
  820. |;
  821. $form->hide_form("id", "type", "old$form->{vc}", "$form->{vc}_id", "orphaned","vc", "title");
  822. print qq|
  823. <table width=100%>
  824. <tr>
  825. <th class=listtop>$form->{title}</th>
  826. </tr>
  827. <tr height="5"></tr>
  828. <tr>
  829. <td>
  830. <table>
  831. <tr>
  832. <th align=right>|.$locale->text('Number').qq|</th>
  833. <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
  834. <th align=right>|.$locale->text('Description').qq|</th>
  835. <td>$description</td>
  836. </tr>
  837. $name
  838. <tr>
  839. <th align=right>|.$locale->text('Startdate').qq|</th>
  840. <td><input name=startdate size=11 title="($myconfig{dateformat})" value=$form->{startdate}></td>
  841. <th align=right>|.$locale->text('Enddate').qq|</th>
  842. <td><input name=enddate size=11 title="($myconfig{dateformat})" value=$form->{enddate}></td>
  843. </tr>
  844. </table>
  845. </td>
  846. </tr>
  847. <tr>
  848. <td><hr size=3 noshade></td>
  849. </tr>
  850. </table>
  851. |;
  852. }
  853. sub project_footer {
  854. $form->hide_form(qw(callback path login sessionid));
  855. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  856. );
  857. if ($myconfig{acs} !~ /Projects--Add Project/) {
  858. $button{'Save'} = { ndx => 3, key => 'S', value => $locale->text('Save') };
  859. if ($form->{id} && $form->{orphaned}) {
  860. $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') };
  861. }
  862. }
  863. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  864. if ($form->{menubar}) {
  865. require "$form->{path}/menu.pl";
  866. &menubar;
  867. }
  868. print qq|
  869. </form>
  870. </body>
  871. </html>
  872. |;
  873. }
  874. sub save {
  875. if ($form->{translation}) {
  876. PE->save_translation(\%myconfig, \%$form);
  877. $form->redirect($locale->text('Translations saved!'));
  878. exit;
  879. }
  880. if ($form->{type} eq 'project') {
  881. if ($form->{"select$form->{vc}"}) {
  882. ($null, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
  883. } else {
  884. if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
  885. if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
  886. &select_name;
  887. exit;
  888. }
  889. if ($rv == 1) {
  890. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  891. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  892. $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  893. }
  894. }
  895. }
  896. PE->save_project(\%myconfig, \%$form);
  897. $form->redirect($locale->text('Project saved!'));
  898. }
  899. if ($form->{type} eq 'partsgroup') {
  900. $form->isblank("partsgroup", $locale->text('Group missing!'));
  901. PE->save_partsgroup(\%myconfig, \%$form);
  902. $form->redirect($locale->text('Group saved!'));
  903. }
  904. if ($form->{type} eq 'pricegroup') {
  905. $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
  906. PE->save_pricegroup(\%myconfig, \%$form);
  907. $form->redirect($locale->text('Pricegroup saved!'));
  908. }
  909. if ($form->{type} eq 'job') {
  910. if ($form->{"select$form->{vc}"}) {
  911. ($null, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
  912. } else {
  913. if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
  914. if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
  915. &select_name;
  916. exit;
  917. }
  918. if ($rv == 1) {
  919. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  920. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  921. $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  922. }
  923. }
  924. }
  925. PE->save_job(\%myconfig, \%$form);
  926. $form->redirect($locale->text('Job saved!'));
  927. }
  928. }
  929. sub delete {
  930. if ($form->{translation}) {
  931. PE->delete_translation(\%myconfig, \%$form);
  932. $form->redirect($locale->text('Translation deleted!'));
  933. } else {
  934. if ($form->{type} eq 'project') {
  935. PE->delete_project(\%myconfig, \%$form);
  936. $form->redirect($locale->text('Project deleted!'));
  937. }
  938. if ($form->{type} eq 'job') {
  939. PE->delete_job(\%myconfig, \%$form);
  940. $form->redirect($locale->text('Job deleted!'));
  941. }
  942. if ($form->{type} eq 'partsgroup') {
  943. PE->delete_partsgroup(\%myconfig, \%$form);
  944. $form->redirect($locale->text('Group deleted!'));
  945. }
  946. if ($form->{type} eq 'pricegroup') {
  947. PE->delete_pricegroup(\%myconfig, \%$form);
  948. $form->redirect($locale->text('Pricegroup deleted!'));
  949. }
  950. }
  951. }
  952. sub partsgroup_report {
  953. $form->{partsgroup} = $form->unescape($form->{partsgroup});
  954. PE->partsgroups(\%myconfig, \%$form);
  955. $href = "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  956. $form->sort_order();
  957. $callback = "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  958. if ($form->{status} eq 'all') {
  959. $option = $locale->text('All');
  960. }
  961. if ($form->{status} eq 'orphaned') {
  962. $option .= $locale->text('Orphaned');
  963. }
  964. if ($form->{partsgroup}) {
  965. $callback .= "&partsgroup=$form->{partsgroup}";
  966. $option .= "\n<br>".$locale->text('Group')." : $form->{partsgroup}";
  967. }
  968. @column_index = $form->sort_columns(qw(partsgroup));
  969. $column_header{partsgroup} = qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>|.$locale->text('Group').qq|</a></th>|;
  970. $form->{title} = $locale->text('Groups');
  971. $form->header;
  972. print qq|
  973. <body>
  974. <table width=100%>
  975. <tr>
  976. <th class=listtop>$form->{title}</th>
  977. </tr>
  978. <tr height="5"></tr>
  979. <tr>
  980. <td>$option</td>
  981. </tr>
  982. <tr>
  983. <td>
  984. <table width=100%>
  985. <tr class=listheading>
  986. |;
  987. for (@column_index) { print "$column_header{$_}\n" }
  988. print qq|
  989. </tr>
  990. |;
  991. # escape callback
  992. $form->{callback} = $callback;
  993. # escape callback for href
  994. $callback = $form->escape($callback);
  995. foreach $ref (@{ $form->{item_list} }) {
  996. $i++; $i %= 2;
  997. print qq|
  998. <tr valign=top class=listrow$i>
  999. |;
  1000. $column_data{partsgroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partsgroup}</td>|;
  1001. for (@column_index) { print "$column_data{$_}\n" }
  1002. print "
  1003. </tr>
  1004. ";
  1005. }
  1006. $i = 1;
  1007. if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) {
  1008. $button{'Goods & Services--Add Group'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Group').qq|"> |;
  1009. $button{'Goods & Services--Add Group'}{order} = $i++;
  1010. foreach $item (split /;/, $myconfig{acs}) {
  1011. delete $button{$item};
  1012. }
  1013. }
  1014. print qq|
  1015. </table>
  1016. </td>
  1017. </tr>
  1018. <tr>
  1019. <td><hr size=3 noshade></td>
  1020. </tr>
  1021. </table>
  1022. <br>
  1023. <form method=post action=$form->{script}>
  1024. |;
  1025. $form->hide_form(qw(callback type path login sessionid));
  1026. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  1027. print $item->{code};
  1028. }
  1029. if ($form->{menubar}) {
  1030. require "$form->{path}/menu.pl";
  1031. &menubar;
  1032. }
  1033. print qq|
  1034. </form>
  1035. </body>
  1036. </html>
  1037. |;
  1038. }
  1039. sub partsgroup_header {
  1040. $form->{action} =~ s/_.*//;
  1041. $form->{title} = $locale->text(ucfirst $form->{action} . " Group");
  1042. # $locale->text('Add Group')
  1043. # $locale->text('Edit Group')
  1044. $form->{partsgroup} = $form->quote($form->{partsgroup});
  1045. $form->header;
  1046. print qq|
  1047. <body>
  1048. <form method=post action=$form->{script}>
  1049. <input type=hidden name=id value=$form->{id}>
  1050. <input type=hidden name=type value=$form->{type}>
  1051. <table width=100%>
  1052. <tr>
  1053. <th class=listtop>$form->{title}</th>
  1054. </tr>
  1055. <tr height="5"></tr>
  1056. <tr>
  1057. <td>
  1058. <table width=100%>
  1059. <tr>
  1060. <th align=right>|.$locale->text('Group').qq|</th>
  1061. <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
  1062. </tr>
  1063. </table>
  1064. </td>
  1065. </tr>
  1066. <tr>
  1067. <td colspan=2><hr size=3 noshade></td>
  1068. </tr>
  1069. </table>
  1070. |;
  1071. }
  1072. sub partsgroup_footer {
  1073. $form->hide_form(qw(callback path login sessionid));
  1074. if ($myconfig{acs} !~ /Goods \& Services--Add Group/) {
  1075. print qq|
  1076. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
  1077. |;
  1078. if ($form->{id} && $form->{orphaned}) {
  1079. print qq|
  1080. <input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
  1081. }
  1082. }
  1083. if ($form->{menubar}) {
  1084. require "$form->{path}/menu.pl";
  1085. &menubar;
  1086. }
  1087. print qq|
  1088. </form>
  1089. </body>
  1090. </html>
  1091. |;
  1092. }
  1093. sub pricegroup_report {
  1094. $form->{pricegroup} = $form->unescape($form->{pricegroup});
  1095. PE->pricegroups(\%myconfig, \%$form);
  1096. $href = "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  1097. $form->sort_order();
  1098. $callback = "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  1099. if ($form->{status} eq 'all') {
  1100. $option = $locale->text('All');
  1101. }
  1102. if ($form->{status} eq 'orphaned') {
  1103. $option .= $locale->text('Orphaned');
  1104. }
  1105. if ($form->{pricegroup}) {
  1106. $callback .= "&pricegroup=$form->{pricegroup}";
  1107. $option .= "\n<br>".$locale->text('Pricegroup')." : $form->{pricegroup}";
  1108. }
  1109. @column_index = $form->sort_columns(qw(pricegroup));
  1110. $column_header{pricegroup} = qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|.$locale->text('Pricegroup').qq|</th>|;
  1111. $form->{title} = $locale->text('Pricegroups');
  1112. $form->header;
  1113. print qq|
  1114. <body>
  1115. <table width=100%>
  1116. <tr>
  1117. <th class=listtop>$form->{title}</th>
  1118. </tr>
  1119. <tr height="5"></tr>
  1120. <tr>
  1121. <td>$option</td>
  1122. </tr>
  1123. <tr>
  1124. <td>
  1125. <table width=100%>
  1126. <tr class=listheading>
  1127. |;
  1128. for (@column_index) { print "$column_header{$_}\n" }
  1129. print qq|
  1130. </tr>
  1131. |;
  1132. # escape callback
  1133. $form->{callback} = $callback;
  1134. # escape callback for href
  1135. $callback = $form->escape($callback);
  1136. foreach $ref (@{ $form->{item_list} }) {
  1137. $i++; $i %= 2;
  1138. print qq|
  1139. <tr valign=top class=listrow$i>
  1140. |;
  1141. $column_data{pricegroup} = qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|;
  1142. for (@column_index) { print "$column_data{$_}\n" }
  1143. print "
  1144. </tr>
  1145. ";
  1146. }
  1147. $i = 1;
  1148. if ($myconfig{acs} !~ /Goods \& Services--Goods \& Services/) {
  1149. $button{'Goods & Services--Add Pricegroup'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Pricegroup').qq|"> |;
  1150. $button{'Goods & Services--Add Pricegroup'}{order} = $i++;
  1151. foreach $item (split /;/, $myconfig{acs}) {
  1152. delete $button{$item};
  1153. }
  1154. }
  1155. print qq|
  1156. </table>
  1157. </td>
  1158. </tr>
  1159. <tr>
  1160. <td><hr size=3 noshade></td>
  1161. </tr>
  1162. </table>
  1163. <br>
  1164. <form method=post action=$form->{script}>
  1165. |;
  1166. $form->hide_form(qw(callback type path login sessionid));
  1167. foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
  1168. print $item->{code};
  1169. }
  1170. if ($form->{menubar}) {
  1171. require "$form->{path}/menu.pl";
  1172. &menubar;
  1173. }
  1174. print qq|
  1175. </form>
  1176. </body>
  1177. </html>
  1178. |;
  1179. }
  1180. sub pricegroup_header {
  1181. $form->{title} = $locale->text(ucfirst $form->{action} ." Pricegroup");
  1182. # $locale->text('Add Pricegroup')
  1183. # $locale->text('Edit Pricegroup')
  1184. $form->{pricegroup} = $form->quote($form->{pricegroup});
  1185. $form->header;
  1186. print qq|
  1187. <body>
  1188. <form method=post action=$form->{script}>
  1189. <input type=hidden name=id value=$form->{id}>
  1190. <input type=hidden name=type value=$form->{type}>
  1191. <table width=100%>
  1192. <tr>
  1193. <th class=listtop>$form->{title}</th>
  1194. </tr>
  1195. <tr height="5"></tr>
  1196. <tr>
  1197. <td>
  1198. <table width=100%>
  1199. <tr>
  1200. <th align=right>|.$locale->text('Pricegroup').qq|</th>
  1201. <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
  1202. </tr>
  1203. </table>
  1204. </td>
  1205. </tr>
  1206. <tr>
  1207. <td colspan=2><hr size=3 noshade></td>
  1208. </tr>
  1209. </table>
  1210. |;
  1211. }
  1212. sub pricegroup_footer {
  1213. $form->hide_form(qw(callback path login sessionid));
  1214. if ($myconfig{acs} !~ /Goods \& Services--Add Pricegroup/) {
  1215. print qq|
  1216. <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
  1217. |;
  1218. if ($form->{id} && $form->{orphaned}) {
  1219. print qq|
  1220. <input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
  1221. }
  1222. }
  1223. if ($form->{menubar}) {
  1224. require "$form->{path}/menu.pl";
  1225. &menubar;
  1226. }
  1227. print qq|
  1228. </form>
  1229. </body>
  1230. </html>
  1231. |;
  1232. }
  1233. sub translation {
  1234. if ($form->{translation} eq 'description') {
  1235. $form->{title} = $locale->text('Description Translations');
  1236. $sort = qq|<input type=hidden name=sort value=partnumber>|;
  1237. $form->{number} = "partnumber";
  1238. $number = qq|
  1239. <tr>
  1240. <th align=right nowrap>|.$locale->text('Number').qq|</th>
  1241. <td><input name=partnumber size=20></td>
  1242. </tr>
  1243. |;
  1244. }
  1245. if ($form->{translation} eq 'partsgroup') {
  1246. $form->{title} = $locale->text('Group Translations');
  1247. $sort = qq|<input type=hidden name=sort value=partsgroup>|;
  1248. }
  1249. if ($form->{translation} eq 'project') {
  1250. $form->{title} = $locale->text('Project Description Translations');
  1251. $form->{number} = "projectnumber";
  1252. $sort = qq|<input type=hidden name=sort value=projectnumber>|;
  1253. $number = qq|
  1254. <tr>
  1255. <th align=right nowrap>|.$locale->text('Project Number').qq|</th>
  1256. <td><input name=projectnumber size=20></td>
  1257. </tr>
  1258. |;
  1259. }
  1260. $form->header;
  1261. print qq|
  1262. <body>
  1263. <form method=post action=$form->{script}>
  1264. |;
  1265. $form->hide_form(qw(translation title number));
  1266. print qq|
  1267. <table width="100%">
  1268. <tr><th class=listtop>$form->{title}</th></tr>
  1269. <tr height="5"></tr>
  1270. <tr valign=top>
  1271. <td>
  1272. <table>
  1273. $number
  1274. <tr>
  1275. <th align=right nowrap>|.$locale->text('Description').qq|</th>
  1276. <td colspan=3><input name=description size=40></td>
  1277. </tr>
  1278. </table>
  1279. </td>
  1280. </tr>
  1281. <tr><td><hr size=3 noshade></td></tr>
  1282. </table>
  1283. <input type=hidden name=nextsub value=list_translations>
  1284. $sort
  1285. |;
  1286. $form->hide_form(qw(path login sessionid));
  1287. print qq|
  1288. <br>
  1289. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  1290. </form>
  1291. </body>
  1292. </html>
  1293. |;
  1294. }
  1295. sub list_translations {
  1296. $title = $form->escape($form->{title},1);
  1297. $callback = "$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&translation=$form->{translation}&number=$form->{number}&title=$title";
  1298. if ($form->{"$form->{number}"}) {
  1299. $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|;
  1300. $option .= $locale->text('Number').qq| : $form->{"$form->{number}"}<br>|;
  1301. }
  1302. if ($form->{description}) {
  1303. $callback .= "&description=$form->{description}";
  1304. $description = $form->{description};
  1305. $description =~ s/\r?\n/<br>/g;
  1306. $option .= $locale->text('Description').qq| : $form->{description}<br>|;
  1307. }
  1308. if ($form->{translation} eq 'partsgroup') {
  1309. @column_index = qw(description language translation);
  1310. $form->{sort} = "";
  1311. } else {
  1312. @column_index = $form->sort_columns("$form->{number}", "description", "language", "translation");
  1313. }
  1314. &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form);
  1315. $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
  1316. $href = $callback;
  1317. $form->sort_order();
  1318. $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
  1319. $column_header{"$form->{number}"} = qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|.$locale->text('Number').qq|</a></th>|;
  1320. $column_header{description} = qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
  1321. $column_header{language} = qq|<th nowrap class=listheading>|.$locale->text('Language').qq|</a></th>|;
  1322. $column_header{translation} = qq|<th nowrap width=40% class=listheading>|.$locale->text('Translation').qq|</a></th>|;
  1323. $form->header;
  1324. print qq|
  1325. <body>
  1326. <table width=100%>
  1327. <tr>
  1328. <th class=listtop>$form->{title}</th>
  1329. </tr>
  1330. <tr height="5"></tr>
  1331. <tr><td>$option</td></tr>
  1332. <tr>
  1333. <td>
  1334. <table width=100%>
  1335. <tr class=listheading>
  1336. |;
  1337. for (@column_index) { print "\n$column_header{$_}" }
  1338. print qq|
  1339. </tr>
  1340. |;
  1341. # add order to callback
  1342. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1343. # escape callback for href
  1344. $callback = $form->escape($callback);
  1345. if (@{ $form->{translations} }) {
  1346. $sameitem = $form->{translations}->[0]->{$form->{sort}};
  1347. }
  1348. foreach $ref (@{ $form->{translations} }) {
  1349. $ref->{description} =~ s/\r?\n/<br>/g;
  1350. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1351. $column_data{description} = "<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}&nbsp;</a></td>";
  1352. $i++; $i %= 2;
  1353. print "<tr class=listrow$i>";
  1354. for (@column_index) { print "\n$column_data{$_}" }
  1355. print qq|
  1356. </tr>
  1357. |;
  1358. }
  1359. print qq|
  1360. </table>
  1361. </td>
  1362. </tr>
  1363. <tr><td><hr size=3 noshade></td></tr>
  1364. </table>
  1365. |;
  1366. print qq|
  1367. <br>
  1368. <form method=post action=$form->{script}>
  1369. <input name=callback type=hidden value="$form->{callback}">
  1370. |;
  1371. $form->hide_form(qw(path login sessionid));
  1372. if ($form->{menubar}) {
  1373. require "$form->{path}/menu.pl";
  1374. &menubar;
  1375. }
  1376. print qq|
  1377. </form>
  1378. </body>
  1379. </html>
  1380. |;
  1381. }
  1382. sub edit_translation {
  1383. &{ "PE::$form->{translation}_translations" }("", \%myconfig, \%$form);
  1384. $form->error($locale->text('Languages not defined!')) unless @{ $form->{all_language} };
  1385. $form->{selectlanguage} = qq|<option>\n|;
  1386. for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
  1387. $form->{"$form->{number}"} = $form->{translations}->[0]->{"$form->{number}"};
  1388. $form->{description} = $form->{translations}->[0]->{description};
  1389. $form->{description} =~ s/\r?\n/<br>/g;
  1390. shift @{ $form->{translations} };
  1391. $i = 1;
  1392. foreach $row (@{ $form->{translations} }) {
  1393. $form->{"language_code_$i"} = $row->{code};
  1394. $form->{"translation_$i"} = $row->{translation};
  1395. $i++;
  1396. }
  1397. $form->{translation_rows} = $i - 1;
  1398. $form->{title} = $locale->text('Edit Description Translations');
  1399. &translation_header;
  1400. &translation_footer;
  1401. }
  1402. sub translation_header {
  1403. $form->{translation_rows}++;
  1404. $form->{selectlanguage} = $form->unescape($form->{selectlanguage});
  1405. for $i (1 .. $form->{translation_rows}) {
  1406. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1407. if ($form->{"language_code_$i"}) {
  1408. $form->{"selectlanguage_$i"} =~ s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
  1409. }
  1410. }
  1411. $form->{selectlanguage} = $form->escape($form->{selectlanguage},1);
  1412. $form->header;
  1413. print qq|
  1414. <body>
  1415. <form method=post action=$form->{script}>
  1416. <input type=hidden name=$form->{number} value="|.$form->quote($form->{"$form->{number}"}).qq|">
  1417. <input type=hidden name=description value="|.$form->quote($form->{description}).qq|">
  1418. |;
  1419. $form->hide_form(qw(id trans_id selectlanguage translation_rows number translation title));
  1420. print qq|
  1421. <table width="100%">
  1422. <tr><th class=listtop>$form->{title}</th></tr>
  1423. <tr height="5"></tr>
  1424. <tr valign=top>
  1425. <td>
  1426. <table width=100%>
  1427. <tr>
  1428. <td align=left>$form->{"$form->{number}"}</th>
  1429. <td align=left>$form->{description}</th>
  1430. </tr>
  1431. <tr>
  1432. <tr>
  1433. <th class=listheading>|.$locale->text('Language').qq|</th>
  1434. <th class=listheading>|.$locale->text('Translation').qq|</th>
  1435. </tr>
  1436. |;
  1437. for $i (1 .. $form->{translation_rows}) {
  1438. if (($rows = $form->numtextrows($form->{"translation_$i"}, 40)) > 1) {
  1439. $translation = qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|;
  1440. } else {
  1441. $translation = qq|<input name="translation_$i" size=40 value="$form->{"translation_$i"}">|;
  1442. }
  1443. print qq|
  1444. <tr valign=top>
  1445. <td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>
  1446. <td>$translation</td>
  1447. </tr>
  1448. |;
  1449. }
  1450. print qq|
  1451. </table>
  1452. </td>
  1453. </tr>
  1454. <tr>
  1455. <td><hr size=3 noshade></td>
  1456. </tr>
  1457. </table>
  1458. |;
  1459. }
  1460. sub translation_footer {
  1461. $form->hide_form(qw(path login sessionid callback));
  1462. %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  1463. 'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
  1464. 'Delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
  1465. );
  1466. if (! $form->{trans_id}) {
  1467. delete $button{'Delete'};
  1468. }
  1469. for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
  1470. if ($form->{menubar}) {
  1471. require "$form->{path}/menu.pl";
  1472. &menubar;
  1473. }
  1474. print qq|
  1475. </form>
  1476. </body>
  1477. </html>
  1478. |;
  1479. }
  1480. sub update {
  1481. if ($form->{translation}) {
  1482. @flds = qw(language translation);
  1483. $count = 0;
  1484. @a = ();
  1485. for $i (1 .. $form->{translation_rows}) {
  1486. if ($form->{"language_code_$i"} ne "") {
  1487. push @a, {};
  1488. $j = $#a;
  1489. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1490. $count++;
  1491. }
  1492. }
  1493. $form->redo_rows(\@flds, \@a, $count, $form->{translation_rows});
  1494. $form->{translation_rows} = $count;
  1495. &translation_header;
  1496. &translation_footer;
  1497. exit;
  1498. }
  1499. if ($form->{type} =~ /(job|project)/) {
  1500. # $locale->text('Customer not on file!')
  1501. # $locale->text('Vendor not on file!')
  1502. for (qw(production listprice sellprice weight)) { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
  1503. $form->{projectnumber} = $form->update_defaults(\%myconfig, "projectnumber") unless $form->{projectnumber};
  1504. if ($form->{"select$form->{vc}"}) {
  1505. if ($form->{startdate} ne $form->{oldstartdate} || $form->{enddate} ne $form->{oldenddate}) {
  1506. PE->get_customer(\%myconfig, \%$form);
  1507. if (@{ $form->{"all_$form->{vc}"} }) {
  1508. $form->{"select$form->{vc}"} = qq|<option>\n|;
  1509. for (@{ $form->{"all_$form->{vc}"} }) { $form->{"select$form->{vc}"} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  1510. }
  1511. }
  1512. $form->{"old$form->{vc}"} = $form->{"$form->{vc}"};
  1513. ($null, $form->{"$form->{vc}_id"}) = split /--/, $form->{"$form->{vc}"};
  1514. } else {
  1515. if ($form->{"old$form->{vc}"} ne qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|) {
  1516. if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
  1517. &select_name;
  1518. exit;
  1519. }
  1520. if ($rv == 1) {
  1521. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  1522. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  1523. $form->{"old$form->{vc}"} = qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  1524. } else {
  1525. $msg = ucfirst $form->{vc} ." not on file!";
  1526. $form->error($locale->text($msg));
  1527. }
  1528. }
  1529. }
  1530. }
  1531. &display_form;
  1532. }
  1533. sub select_name {
  1534. $label = ucfirst $form->{vc};
  1535. @column_index = qw(ndx name address);
  1536. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  1537. $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
  1538. $column_data{address} = qq|<th class=listheading colspan=5>|.$locale->text('Address').qq|</th>|;
  1539. $form->header;
  1540. $title = $locale->text('Select from one of the names below');
  1541. print qq|
  1542. <body>
  1543. <form method=post action=$form->{script}>
  1544. <table width=100%>
  1545. <tr>
  1546. <th class=listtop>$title</th>
  1547. </tr>
  1548. <tr space=5></tr>
  1549. <tr>
  1550. <td>
  1551. <table width=100%>
  1552. <tr class=listheading>|;
  1553. for (@column_index) { print "\n$column_data{$_}" }
  1554. print qq|
  1555. </tr>
  1556. |;
  1557. @column_index = qw(ndx name address city state zipcode country);
  1558. my $i = 0;
  1559. foreach $ref (@{ $form->{name_list} }) {
  1560. $checked = ($i++) ? "" : "checked";
  1561. $ref->{name} = $form->quote($ref->{name});
  1562. $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  1563. $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
  1564. $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
  1565. for (qw(city state zipcode country)) { $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>| }
  1566. $j++; $j %= 2;
  1567. print qq|
  1568. <tr class=listrow$j>|;
  1569. for (@column_index) { print "\n$column_data{$_}" }
  1570. print qq|
  1571. </tr>
  1572. <input name="new_id_$i" type=hidden value=$ref->{id}>
  1573. |;
  1574. }
  1575. print qq|
  1576. </table>
  1577. </td>
  1578. </tr>
  1579. <tr>
  1580. <td><hr size=3 noshade></td>
  1581. </tr>
  1582. </table>
  1583. <input name=lastndx type=hidden value=$i>
  1584. |;
  1585. # delete variables
  1586. for (qw(action nextsub name_list)) { delete $form->{$_} }
  1587. $form->hide_form;
  1588. print qq|
  1589. <input type=hidden name=nextsub value=name_selected>
  1590. <br>
  1591. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  1592. </form>
  1593. </body>
  1594. </html>
  1595. |;
  1596. }
  1597. sub name_selected {
  1598. # replace the variable with the one checked
  1599. # index for new item
  1600. $i = $form->{ndx};
  1601. $form->{$form->{vc}} = $form->{"new_name_$i"};
  1602. $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
  1603. $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  1604. # delete all the new_ variables
  1605. for $i (1 .. $form->{lastndx}) {
  1606. for (qw(id name)) { delete $form->{"new_${_}_$i"} }
  1607. }
  1608. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  1609. &display_form;
  1610. }
  1611. sub display_form {
  1612. &{ "$form->{type}_header" };
  1613. &{ "$form->{type}_footer" };
  1614. }
  1615. sub continue { &{ $form->{nextsub} } };
  1616. sub add_group { &add }
  1617. sub add_project { &add }
  1618. sub add_job { &add }
  1619. sub add_pricegroup { &add }
  1620. sub project_sales_order {
  1621. PE->project_sales_order(\%myconfig, \%$form);
  1622. if (@{ $form->{all_years} }) {
  1623. $form->{selectaccountingyear} = "<option>\n";
  1624. for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
  1625. $form->{selectaccountingmonth} = "<option>\n";
  1626. for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
  1627. $selectfrom = qq|
  1628. <tr>
  1629. <th align=right>|.$locale->text('Period').qq|</th>
  1630. <td colspan=3>
  1631. <select name=month>$form->{selectaccountingmonth}</select>
  1632. <select name=year>$form->{selectaccountingyear}</select>
  1633. <input name=interval class=radio type=radio value=0 checked>&nbsp;|.$locale->text('Current').qq|
  1634. <input name=interval class=radio type=radio value=1>&nbsp;|.$locale->text('Month').qq|
  1635. <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
  1636. <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
  1637. </td>
  1638. </tr>
  1639. |;
  1640. }
  1641. $fromto = qq|
  1642. <tr>
  1643. <th align=right nowrap>|.$locale->text('Transaction Dates').qq|</th>
  1644. <td>|.$locale->text('From').qq| <input name=transdatefrom size=11 title="$myconfig{dateformat}">
  1645. |.$locale->text('To').qq| <input name=transdateto size=11 title="$myconfig{dateformat}"></td>
  1646. </tr>
  1647. $selectfrom
  1648. |;
  1649. if (@{ $form->{all_project} }) {
  1650. $form->{selectprojectnumber} = "<option>\n";
  1651. for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
  1652. } else {
  1653. $form->error($locale->text('No open Projects!'));
  1654. }
  1655. if (@{ $form->{all_employee} }) {
  1656. $form->{selectemployee} = "<option>\n";
  1657. for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
  1658. $employee = qq|
  1659. <tr>
  1660. <th align=right nowrap>|.$locale->text('Employee').qq|</th>
  1661. <td><select name=employee>$form->{selectemployee}</select></td>
  1662. </tr>
  1663. |;
  1664. }
  1665. $form->{title} = $locale->text('Generate Sales Orders');
  1666. $form->{vc} = "customer";
  1667. $form->{type} = "sales_order";
  1668. $form->header;
  1669. print qq|
  1670. <body>
  1671. <form method=post action=$form->{script}>
  1672. <table width=100%>
  1673. <tr>
  1674. <th class=listtop>$form->{title}</th>
  1675. </tr>
  1676. <tr height="5"></tr>
  1677. <tr valign=top>
  1678. <td>
  1679. <table>
  1680. <tr>
  1681. <th align=right>|.$locale->text('Project').qq|</th>
  1682. <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
  1683. </tr>
  1684. $employee
  1685. $fromto
  1686. <tr>
  1687. <th></th>
  1688. <td><input name=summary type=radio class=radio value=1 checked> |.$locale->text('Summary').qq|
  1689. <input name=summary type=radio class=radio value=0> |.$locale->text('Detail').qq|
  1690. </td>
  1691. </tr>
  1692. </table>
  1693. </td>
  1694. </tr>
  1695. <tr>
  1696. <td><hr size=3 noshade></td>
  1697. </tr>
  1698. </table>
  1699. |;
  1700. $form->{nextsub} = "project_jcitems_list";
  1701. $form->hide_form(qw(path login sessionid nextsub type vc));
  1702. print qq|
  1703. <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
  1704. </form>
  1705. |;
  1706. if ($form->{menubar}) {
  1707. require "$form->{path}/menu.pl";
  1708. &menubar;
  1709. }
  1710. print qq|
  1711. </body>
  1712. </html>
  1713. |;
  1714. }
  1715. sub project_jcitems_list {
  1716. $form->{projectnumber} = $form->unescape($form->{projectnumber});
  1717. $form->{employee} = $form->unescape($form->{employee});
  1718. $form->{callback} = "$form->{script}?action=project_jcitems_list";
  1719. for (qw(month year interval summary transdatefrom transdateto login path sessionid nextsub type vc)) { $form->{callback} .= "&$_=$form->{$_}" }
  1720. for (qw(employe projectnumber)) { $form->{callback} .= "&$_=".$form->escape($form->{$_},1) }
  1721. PE->get_jcitems(\%myconfig, \%$form);
  1722. # flatten array
  1723. $i = 1;
  1724. foreach $ref (@{ $form->{jcitems} }) {
  1725. if ($form->{summary}) {
  1726. $thisitem = qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
  1727. if ($thisitem eq $sameitem) {
  1728. $i--;
  1729. for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} }
  1730. $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}";
  1731. if ($form->{"notes_$i"}) {
  1732. $form->{"notes_$i"} .= qq|\n\n$ref->{notes}|;
  1733. } else {
  1734. $form->{"notes_$i"} = $ref->{notes};
  1735. }
  1736. } else {
  1737. for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
  1738. $form->{"checked_$i"} = 1;
  1739. $form->{"$form->{vc}_$i"} = $ref->{$form->{vc}};
  1740. $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
  1741. }
  1742. $sameitem = qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
  1743. } else {
  1744. for (keys %$ref) { $form->{"${_}_$i"} = $ref->{$_} }
  1745. $form->{"checked_$i"} = 1;
  1746. $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
  1747. }
  1748. $i++;
  1749. }
  1750. $form->{rowcount} = $i - 1;
  1751. for $i (1 .. $form->{rowcount}) {
  1752. for (qw(qty allocated)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
  1753. for (qw(amount sellprice)) { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) }
  1754. }
  1755. &jcitems;
  1756. }
  1757. sub jcitems {
  1758. # $locale->text('Customer')
  1759. # $locale->text('Vendor')
  1760. $vc = ucfirst $form->{vc};
  1761. @column_index = qw(id projectnumber name);
  1762. if (!$form->{summary}) {
  1763. push @column_index, qw(transdate);
  1764. }
  1765. push @column_index, qw(partnumber description qty amount);
  1766. $column_header{id} = qq|<th>&nbsp;</th>|;
  1767. $column_header{transdate} = qq|<th class=listheading>|.$locale->text('Date').qq|</th>|;
  1768. $column_header{partnumber} = qq|<th class=listheading>|.$locale->text('Service Code').qq|<br>|.$locale->text('Part Number').qq|</th>|;
  1769. $column_header{projectnumber} = qq|<th class=listheading>|.$locale->text('Project Number').qq|</th>|;
  1770. $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</th>|;
  1771. $column_header{name} = qq|<th class=listheading>$vc</th>|;
  1772. $column_header{qty} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
  1773. $column_header{amount} = qq|<th class=listheading>|.$locale->text('Amount').qq|</th>|;
  1774. if ($form->{type} eq 'sales_order') {
  1775. $form->{title} = $locale->text('Generate Sales Orders');
  1776. }
  1777. $form->header;
  1778. print qq|
  1779. <body>
  1780. <form method=post action=$form->{script}>
  1781. <table width=100%>
  1782. <tr>
  1783. <th class=listtop>$form->{title}</th>
  1784. </tr>
  1785. <tr height="5"></tr>
  1786. <tr>
  1787. <td>
  1788. <table width=100%>
  1789. <tr class=listheading>|;
  1790. for (@column_index) { print "\n$column_header{$_}" }
  1791. print qq|
  1792. </tr>
  1793. |;
  1794. for $i (1 .. $form->{rowcount}) {
  1795. for (@column_index) { $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>| }
  1796. for (qw(qty amount)) { $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>| }
  1797. $checked = ($form->{"checked_$i"}) ? "checked" : "";
  1798. $column_data{id} = qq|<td><input name="checked_$i" class=checkbox type=checkbox value="1" $checked></td>|;
  1799. if ($form->{"$form->{vc}_id_$i"}) {
  1800. $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|;
  1801. $form->hide_form("$form->{vc}_id_$i", "$form->{vc}_$i");
  1802. } else {
  1803. $column_data{name} = qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
  1804. }
  1805. for (qw(projectnumber partnumber description notes)) { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) }
  1806. $form->hide_form(map {"${_}_$i"} qw(id project_id parts_id projectnumber transdate partnumber description notes qty amount taxaccounts sellprice));
  1807. $j++; $j %= 2;
  1808. print "
  1809. <tr class=listrow$j>";
  1810. for (@column_index) { print "\n$column_data{$_}" }
  1811. print qq|
  1812. </tr>
  1813. |;
  1814. }
  1815. print qq|
  1816. </table>
  1817. </td>
  1818. </tr>
  1819. <tr>
  1820. <td><hr size=3 noshade></td>
  1821. </tr>
  1822. </table>
  1823. <br>
  1824. |;
  1825. $form->hide_form(qw(path login sessionid vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback));
  1826. for (split / /, $form->{taxaccounts}) { $form->hide_form("${_}_rate") }
  1827. if ($form->{rowcount}) {
  1828. print qq|
  1829. <input class=submit type=submit name=action value="|.$locale->text('Generate Sales Orders').qq|">|;
  1830. print qq|
  1831. <input class=submit type=submit name=action value="|.$locale->text('Select Customer').qq|">|;
  1832. }
  1833. if ($form->{menubar}) {
  1834. require "$form->{path}/menu.pl";
  1835. &menubar;
  1836. }
  1837. print qq|
  1838. </form>
  1839. </body>
  1840. </html>
  1841. |;
  1842. }
  1843. sub select_customer {
  1844. for (1 .. $form->{rowcount}) {
  1845. last if ($ok = $form->{"ndx_$_"});
  1846. }
  1847. $form->error($locale->text('Nothing selected!')) unless $ok;
  1848. $label = ($form->{vc} eq 'customer') ? $locale->text('Customer') : $locale->text('Vendor');
  1849. $form->header;
  1850. print qq|
  1851. <body onLoad="document.forms[0].$form->{vc}.focus()" />
  1852. <form method=post action=$form->{script}>
  1853. <b>$label</b> <input name=$form->{vc} size=40>
  1854. |;
  1855. $form->{nextsub} = "$form->{vc}_selected";
  1856. $form->{action} = "$form->{vc}_selected";
  1857. $form->hide_form;
  1858. print qq|
  1859. <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
  1860. </form>
  1861. |;
  1862. print qq|
  1863. </body>
  1864. </html>
  1865. |;
  1866. }
  1867. sub customer_selected {
  1868. if (($rv = $form->get_name(\%myconfig, $form->{vc}, $form->{startdate})) > 1) {
  1869. &select_name($form->{vc});
  1870. exit;
  1871. }
  1872. if ($rv == 1) {
  1873. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  1874. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  1875. } else {
  1876. $msg = ($form->{vc} eq 'customer') ? $locale->text('Customer not on file!') : $locale->text('Vendor not on file!');
  1877. $form->error($locale->text($msg));
  1878. }
  1879. &display_form;
  1880. }
  1881. sub sales_order_header {
  1882. for (1 .. $form->{rowcount}) {
  1883. if ($form->{"ndx_$_"}) {
  1884. $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
  1885. $form->{"$form->{vc}_$_"} = $form->{"$form->{vc}"};
  1886. }
  1887. }
  1888. }
  1889. sub sales_order_footer { &jcitems }
  1890. sub generate_sales_orders {
  1891. for $i (1 .. $form->{rowcount}) {
  1892. $form->error($locale->text('Customer missing!')) if ($form->{"checked_$i"} && !$form->{"customer_$i"});
  1893. }
  1894. for $i (1 .. $form->{rowcount}) {
  1895. if ($form->{"checked_$i"}) {
  1896. push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} }, {
  1897. partnumber => $form->{"partnumber_$i"},
  1898. id => $form->{"parts_id_$i"},
  1899. description => $form->{"description_$i"},
  1900. qty => $form->{"qty_$i"},
  1901. sellprice => $form->{"sellprice_$i"},
  1902. projectnumber => qq|--$form->{"project_id_$i"}|,
  1903. reqdate => $form->{"transdate_$i"},
  1904. taxaccounts => $form->{"taxaccounts_$i"},
  1905. jcitems => $form->{"id_$i"},
  1906. notes => $form->{"notes_$i"},
  1907. }
  1908. }
  1909. }
  1910. $order = new Form;
  1911. for (keys %{ $form->{order} }) {
  1912. for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} }
  1913. for (split / /, $form->{taxaccounts}) { $order->{"${_}_rate"} = $form->{"${_}_rate"} }
  1914. $i = 0;
  1915. $order->{"$order->{vc}_id"} = $_;
  1916. AA->get_name(\%myconfig, \%$order);
  1917. foreach $ref (@ {$form->{order}{$_} }) {
  1918. $i++;
  1919. for (keys %$ref) { $order->{"${_}_$i"} = $ref->{$_} }
  1920. $taxaccounts = "";
  1921. for (split / /, $order->{taxaccounts}) { $taxaccounts .= qq|$_ | if ($_ =~ /$order->{"taxaccounts_$i"}/) }
  1922. $order->{"taxaccounts_$i"} = $taxaccounts;
  1923. }
  1924. $order->{rowcount} = $i;
  1925. for (qw(currency)) { $order->{$_} = $form->{$_} }
  1926. $order->{ordnumber} = $order->update_defaults(\%myconfig, 'sonumber');
  1927. $order->{transdate} = $order->current_date(\%myconfig);
  1928. $order->{reqdate} = $order->{transdate};
  1929. for (qw(intnotes employee employee_id)) { delete $order->{$_} }
  1930. if (OE->save(\%myconfig, \%$order)) {
  1931. if (! PE->allocate_projectitems(\%myconfig, \%$order)) {
  1932. OE->delete(\%myconfig, \%$order, $spool);
  1933. }
  1934. } else {
  1935. $order->error($locale->text('Failed to save order!'));
  1936. }
  1937. for (keys %$order) { delete $order->{$_} }
  1938. }
  1939. $form->redirect($locale->text('Orders generated!'));
  1940. }