- #=====================================================================
- # LedgerSMB Small Medium Business Accounting
- # http://www.ledgersmb.org/
- #
- # Copyright (C) 2006
- # This work contains copyrighted information from a number of sources all used
- # with permission.
- #
- # This file contains source code included with or based on SQL-Ledger which
- # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
- # under the GNU General Public License version 2 or, at your option, any later
- # version. For a full list including contact information of contributors,
- # maintainers, and copyright holders, see the CONTRIBUTORS file.
- #
- # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
- # Copyright (c) 2005
- #
- # Author: DWS Systems Inc.
- # Web: http://www.sql-ledger.org
- #
- #
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- #======================================================================
- #
- # Job Costing module
- #
- #======================================================================
- use LedgerSMB::JC;
- 1;
- # end of main
- sub add {
- if ($form->{type} eq 'timecard') {
- $form->{title} = $locale->text('Add Time Card');
- }
- if ($form->{type} eq 'storescard') {
- $form->{title} = $locale->text('Add Stores Card');
- }
- $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&project=$form->{project}" unless $form->{callback};
- &{ "prepare_$form->{type}" };
-
- $form->{orphaned} = 1;
- &display_form;
-
- }
- sub edit {
- if ($form->{type} eq 'timecard') {
- $form->{title} = $locale->text('Edit Time Card');
- }
- if ($form->{type} eq 'storescard') {
- $form->{title} = $locale->text('Add Stores Card');
- }
-
- &{ "prepare_$form->{type}" };
-
- &display_form;
-
- }
- sub jcitems_links {
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- foreach $ref (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} .= qq|<option value="$ref->{projectnumber}--$ref->{id}">$ref->{description} ($ref->{description})</option>\n|;
- if ($form->{projectnumber} eq "$ref->{projectnumber}--$ref->{id}") {
- $form->{projectdescription} = $ref->{description};
- }
- }
- } else {
- if ($form->{project} eq 'job') {
- $form->error($locale->text('No open Jobs!'));
- } else {
- $form->error($locale->text('No open Projects!'));
- }
- }
-
- if (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} = "<option>\n";
- foreach $ref (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} .= qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
- if ($form->{partnumber} eq "$ref->{partnumber}--$ref->{id}") {
- if ($form->{partnumber} ne $form->{oldpartnumber}) {
- for (qw(description unit sellprice pricematrix)) { $form->{$_} = $ref->{$_} }
- }
- }
- }
- } else {
- if ($form->{type} eq 'timecard') {
- if ($form->{project} eq 'job') {
- $form->error($locale->text('No Labor codes on file!'));
- } else {
- $form->error($locale->text('No Services on file!'));
- }
- } else {
- $form->error($locale->text('No Parts on file!'));
- }
- }
-
- # employees
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "<option>\n";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- } else {
- $form->error($locale->text('No Employees on file!'));
- }
- }
- sub search {
-
- # accounting years
- $form->all_years(\%myconfig);
- if (@{ $form->{all_years} }) {
- $form->{selectaccountingyear} = "<option>\n";
- for (@{ $form->{all_years} }) { $form->{selectaccountingyear} .= qq|<option>$_\n| }
- $form->{selectaccountingmonth} = "<option>\n";
- for (sort keys %{ $form->{all_month} }) { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| }
- $selectfrom = qq|
- <tr>
- <th align=right>|.$locale->text('Period').qq|</th>
- <td colspan=3>
- <select name=month>$form->{selectaccountingmonth}</select>
- <select name=year>$form->{selectaccountingyear}</select>
- <input name=interval class=radio type=radio value=0 checked> |.$locale->text('Current').qq|
- <input name=interval class=radio type=radio value=1> |.$locale->text('Month').qq|
- <input name=interval class=radio type=radio value=3> |.$locale->text('Quarter').qq|
- <input name=interval class=radio type=radio value=12> |.$locale->text('Year').qq|
- </td>
- </tr>
- |;
- }
- $fromto = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Startdate').qq|</th>
- <td>|.$locale->text('From').qq| <input name=startdatefrom size=11 title="$myconfig{dateformat}">
- |.$locale->text('To').qq| <input name=startdateto size=11 title="$myconfig{dateformat}"></td>
- </tr>
- $selectfrom
- |;
-
- if ($form->{type} eq 'timecard') {
- $form->{title} = $locale->text('Time Cards');
- JC->jcitems_links(\%myconfig, \%$form);
- }
- if ($form->{type} eq 'storescard') {
- $form->{title} = $locale->text('Stores Cards');
- JC->jcitems_links(\%myconfig, \%$form);
- }
- if (@{ $form->{all_project} }) {
- $form->{selectprojectnumber} = "<option>\n";
- for (@{ $form->{all_project} }) { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| }
- }
-
- if (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} = "<option>\n";
- foreach $ref (@{ $form->{all_parts} }) {
- $form->{selectpartnumber} .= qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
- }
- }
-
- if ($form->{project} eq 'job') {
- $joblabel = $locale->text('Job Number');
- $laborlabel = $locale->text('Labor Code');
- } elsif ($form->{project} eq 'project') {
- $joblabel = $locale->text('Project Number');
- $laborlabel = $locale->text('Service Code');
- } else {
- $joblabel = $locale->text('Project/Job Number');
- $laborlabel = $locale->text('Service/Labor Code');
- }
-
- if ($form->{selectprojectnumber}) {
- $jobnumber = qq|
- <tr>
- <th align=right nowrap>$joblabel</th>
- <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
- </tr>
- |;
- }
-
- if ($form->{type} eq 'timecard') {
- # employees
- if (@{ $form->{all_employee} }) {
- $form->{selectemployee} = "<option>\n";
- for (@{ $form->{all_employee} }) { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| }
- } else {
- $form->error($locale->text('No Employees on file!'));
- }
-
- if ($form->{selectpartnumber}) {
- $partnumber = qq|
- <tr>
- <th align=right nowrap>$laborlabel</th>
- <td colspan=3><select name=partnumber>$form->{selectpartnumber}</select></td>
- </tr>
- |;
- }
- $employee = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
- <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
- </tr>
- |;
- $l_time = qq|<td nowrap><input name=l_time class=checkbox type=checkbox value=Y> |.$locale->text('Time').qq|</td>|;
-
- }
- $form->header;
- print qq|
- <body>
- <form method=post action=$form->{script}>
- <table width=100%>
- <tr>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr valign=top>
- <td>
- <table>
- $jobnumber
- $partnumber
- $employee
- $fromto
- <tr>
- <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
- <td>
- <table>
- <tr>
- <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |.$locale->text('Open').qq|</td>
- <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |.$locale->text('Closed').qq|</td>
- </tr>
- <tr>
- $l_time
- <td nowrap><input name=l_allocated class=checkbox type=checkbox value=Y> |.$locale->text('Allocated').qq|</td>
- </tr>
- <tr>
- <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
- </table>
- <input type=hidden name=nextsub value="list_$form->{type}">
- <input type=hidden name=sort value="transdate">
- |;
- $form->hide_form(qw(db path login sessionid project type));
- print qq|
- <br>
- <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
- </form>
- |;
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
- print qq|
- </body>
- </html>
- |;
- }
- sub display_form {
- &{ "$form->{type}_header" };
- &{ "$form->{type}_footer" };
- }
- sub form_header {
- &{ "$form->{type}_header" };
- }
- sub form_footer {
- &{ "form->{type}_footer" };
- }
- sub prepare_timecard {
- $form->{formname} = "timecard";
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
-
- JC->get_jcitems(\%myconfig, \%$form);
- $form->{selectformname} = qq|<option value="timecard">|.$locale->text('Time Card');
-
- foreach $item (qw(in out)) {
- ($form->{"${item}hour"}, $form->{"${item}min"}, $form->{"${item}sec"}) = split /:/, $form->{"checked$item"};
- for (qw(hour min sec)) {
- if (($form->{"$item$_"} *= 1) > 0) {
- $form->{"$item$_"} = substr(qq|0$form->{"$item$_"}|,-2);
- } else {
- $form->{"$item$_"} ||= "";
- }
- }
- }
-
- $form->{checkedin} = $form->{inhour} * 3600 + $form->{inmin} * 60 + $form->{insec};
- $form->{checkedout} = $form->{outhour} * 3600 + $form->{outmin} * 60 + $form->{outsec};
- if ($form->{checkedin} > $form->{checkedout}) {
- $form->{checkedout} = 86400 - ($form->{checkedin} - $form->{checkedout});
- $form->{checkedin} = 0;
- }
- $form->{clocked} = ($form->{checkedout} - $form->{checkedin}) / 3600;
- if ($form->{clocked}) {
- $form->{oldnoncharge} = $form->{clocked} - $form->{qty};
- }
- $form->{oldqty} = $form->{qty};
-
- $form->{noncharge} = $form->format_amount(\%myconfig, $form->{clocked} - $form->{qty}, 4) if $form->{checkedin} != $form->{checkedout};
- $form->{clocked} = $form->format_amount(\%myconfig, $form->{clocked}, 4);
-
- $form->{amount} = $form->{sellprice} * $form->{qty};
- for (qw(sellprice amount)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2) }
- $form->{qty} = $form->format_amount(\%myconfig, $form->{qty}, 4);
- $form->{allocated} = $form->format_amount(\%myconfig, $form->{allocated});
- $form->{employee} .= "--$form->{employee_id}";
- $form->{projectnumber} .= "--$form->{project_id}";
- $form->{partnumber} .= "--$form->{parts_id}";
- $form->{oldpartnumber} = $form->{partnumber};
- if (@{ $form->{all_language} }) {
- $form->{selectlanguage} = "<option>\n";
- for (@{ $form->{all_language} }) { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| }
- }
- &jcitems_links;
- $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum(\%myconfig, $form->{transdate}) <= $form->datetonum(\%myconfig, $form->{closedto}));
-
- $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
- if ($form->{income_accno_id}) {
- $form->{locked} = 1 if $form->{production} == $form->{completed};
- }
- }
- sub timecard_header {
- # set option selected
- for (qw(employee projectnumber partnumber)) {
- $form->{"select$_"} =~ s/ selected//;
- $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
- }
-
- $rows = $form->numtextrows($form->{description}, 50, 8);
- for (qw(transdate checkedin checkedout partnumber)) { $form->{"old$_"} = $form->{$_} }
- for (qw(partnumber description)) { $form->{$_} = $form->quote($form->{$_}) }
- if ($rows > 1) {
- $description = qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
- } else {
- $description = qq|<input name=description size=48 value="$form->{description}">|;
- }
- if ($form->{project} eq 'job') {
- $projectlabel = $locale->text('Job Number');
- $laborlabel = $locale->text('Labor Code');
- $rate = qq|<input type=hidden name=sellprice value=$form->{sellprice}>|;
- } else {
- if ($form->{project} eq 'project') {
- $projectlabel = $locale->text('Project Number');
- $laborlabel = $locale->text('Service Code');
- } else {
- $projectlabel = $locale->text('Project/Job Number');
- $laborlabel = $locale->text('Service/Labor Code');
- }
-
- if ($myconfig{role} ne 'user') {
- $rate = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Chargeout Rate').qq|</th>
- <td><input name=sellprice value=$form->{sellprice}></td>
- <th align=right nowrap>|.$locale->text('Total').qq|</th>
- <td>$form->{amount}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Allocated').qq|</th>
- <td><input name=allocated value=$form->{allocated}></td>
- </tr>
- |;
- } else {
- $rate = qq|
- <tr>
- <th align=right nowrap>|.$locale->text('Chargeout Rate').qq|</th>
- <td>$form->{sellprice}</td>
- <th align=right nowrap>|.$locale->text('Total').qq|</th>
- <td>$form->{amount}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Allocated').qq|</th>
- <td>$form->{allocated}</td>
- </tr>
- <input type=hidden name=sellprice value=$form->{sellprice}>
- <input type=hidden name=allocated value=$form->{allocated}>
- |;
- }
- }
- if ($myconfig{role} eq 'user') {
- $charge = qq|<input type=hidden name=qty value=$form->{qty}>$form->{qty}|;
- } else {
- $charge = qq|<input name=qty value=$form->{qty}>|;
- }
-
- if (($rows = $form->numtextrows($form->{notes}, 40, 6)) < 2) {
- $rows = 2;
- }
- $notes = qq|<tr>
- <th align=right>|.$locale->text('Notes').qq|</th>
- <td colspan=3><textarea name="notes" rows=$rows cols=46 wrap=soft>$form->{notes}</textarea>
- </td>
- </tr>
- |;
- ##################
- ($null, $form->{oldproject_id}) = split /--/, $form->{projectnumber};
-
- $form->header;
- print qq|
- <body>
- <form method=post action="$form->{script}">
- |;
- $form->hide_form(qw(id type media format printed queued title closedto locked oldtransdate oldcheckedin oldcheckedout oldpartnumber project oldqty oldnoncharge pricematrix oldproject_id));
- print qq|
- <table width=100%>
- <tr class=listtop>
- <th class=listtop>$form->{title}</th>
- </tr>
- <tr height="5"></tr>
- <tr>
- <td>
- <table>
- <tr>
- <td>
- <table>
- <tr>
- <th align=right nowrap>|.$locale->text('Employee').qq|</th>
- <td><select name=employee>$form->{selectemployee}</select></td>
- </tr>
- <tr>
- <th align=right nowrap>$projectlabel</th>
- <td><select name=projectnumber>$form->{selectprojectnumber}</select>
- </td>
- <td></td>
- <td>$form->{projectdescription}</td>
- <input type=hidden name=projectdescription value="|.$form->quote($form->{projectdescription}).qq|">
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Date worked').qq|</th>
- <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
- </tr>
- <tr>
- <th align=right nowrap>$laborlabel</th>
- <td><select name=partnumber>$form->{selectpartnumber}</select></td>
- </tr>
- <tr valign=top>
- <th align=right nowrap>|.$locale->text('Description').qq|</th>
- <td colspan=3>$description</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Time In').qq|</th>
- <td>
- <table>
- <tr>
- <td><input name=inhour title="hh" size=3 maxlength=2 value=$form->{inhour}></td>
- <td><input name=inmin title="mm" size=3 maxlength=2 value=$form->{inmin}></td>
- <td><input name=insec title="ss" size=3 maxlength=2 value=$form->{insec}></td>
- </tr>
- </table>
- </td>
- <th align=right nowrap>|.$locale->text('Time Out').qq|</th>
- <td>
- <table>
- <tr>
- <td><input name=outhour title="hh" size=3 maxlength=2 value=$form->{outhour}></td>
- <td><input name=outmin title="mm" size=3 maxlength=2 value=$form->{outmin}></td>
- <td><input name=outsec title="ss" size=3 maxlength=2 value=$form->{outsec}></td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Clocked').qq|</th>
- <td>$form->{clocked}</td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Non-chargeable').qq|</th>
- <td><input name=noncharge value=$form->{noncharge}></td>
- </tr>
- <tr>
- <th align=right nowrap>|.$locale->text('Chargeable').qq|</th>
- <td>$charge</td>
- </tr>
- $rate
- $notes
- </table>
- </td>
- </tr>
- |;
- }
- sub timecard_footer {
- print qq|
- </table>
- </td>
- </tr>
- <tr>
- <td><hr size=3 noshade></td>
- </tr>
- <tr>
- <td>
- |;
- &print_options;
- print qq|
- </td>
- </tr>
- </table>
- <br>
- |;
- $transdate = $form->datetonum(\%myconfig, $form->{transdate});
- $closedto = $form->datetonum(\%myconfig, $form->{closedto});
- if (! $form->{readonly}) {
- # type=submit $locale->text('Update')
- # type=submit $locale->text('Print')
- # type=submit $locale->text('Save')
- # type=submit $locale->text('Print and Save')
- # type=submit $locale->text('Save as new')
- # type=submit $locale->text('Print and Save as new')
- # type=submit $locale->text('Delete')
- %button = ('update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
- 'print' => { ndx => 2, key => 'P', value => $locale->text('Print') },
- 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
- 'print_and_save' => { ndx => 6, key => 'R', value => $locale->text('Print and Save') },
- 'save_as_new' => { ndx => 7, key => 'N', value => $locale->text('Save as new') },
- 'print_and_save_as_new' => { ndx => 8, key => 'W', value => $locale->text('Print and Save as new') },
-
- 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
- );
- %a = ();
-
- if ($form->{id}) {
-
- if (!$form->{locked}) {
- for ('update', 'print', 'save', 'save_as_new') { $a{$_} = 1 }
-
- if (${LedgerSMB::Sysconfig::latex}) {
- for ('print_and_save', 'print_and_save_as_new') { $a{$_} = 1 }
- }
- if ($form->{orphaned}) {
- $a{'delete'} = 1;
- }
-
- }
- } else {
- if ($transdate > $closedto) {
-
- for ('update', 'print', 'save') { $a{$_} = 1 }
- if (${LedgerSMB::Sysconfig::latex}) {
- $a{'print_and_save'} = 1;
- }
- }
- }
- }
- for (keys %button) { delete $button{$_} if ! $a{$_} }
- for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) }
-
- if ($form->{lynx}) {
- require "bin/menu.pl";
- &menubar;
- }
- $form->hide_form(qw(callback path login sessionid));
-
- print qq|
- </form>
- </body>
- </html>
- |;
- }
- sub prepare_storescard {
- $form->{formname} = "storescard";
- $form->{format} = "postscript" if $myconfig{printer};
- $form->{media} = $myconfig{printer};
- JC->get_jcitems(\%myconfig, \%$form);
-
|