Revision a596e63e
Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt
SL/IC.pm | ||
---|---|---|
792 | 792 |
# top100 |
793 | 793 |
# |
794 | 794 |
# simple filter strings (every one of those also has a column flag prefixed with 'l_' associated): |
795 |
# partnumber ean description partsgroup microfiche drawing
|
|
795 |
# partnumber ean description partsgroup microfiche drawing |
|
796 | 796 |
# |
797 | 797 |
# column flags: |
798 |
# l_partnumber l_description l_listprice l_sellprice l_lastcost l_priceupdate l_weight l_unit l_bin l_rop l_image l_drawing l_microfiche l_partsgroup
|
|
798 |
# l_partnumber l_description l_listprice l_sellprice l_lastcost l_priceupdate l_weight l_unit l_bin l_rop l_image l_drawing l_microfiche l_partsgroup |
|
799 | 799 |
# |
800 | 800 |
# exclusives: |
801 | 801 |
# itemstatus = active | onhand | short | obsolete | orphaned |
... | ... | |
804 | 804 |
# joining filters: |
805 | 805 |
# make model - makemodel |
806 | 806 |
# serialnumber transdatefrom transdateto - invoice/orderitems |
807 |
#
|
|
807 |
# |
|
808 | 808 |
# binary flags: |
809 |
# bought sold onorder ordered rfq quoted - aggreg joins with invoices/orders
|
|
809 |
# bought sold onorder ordered rfq quoted - aggreg joins with invoices/orders |
|
810 | 810 |
# l_linetotal l_subtotal - aggreg joins to display totals (complicated) - NOT IMPLEMENTED here, implementation at frontend |
811 | 811 |
# l_soldtotal - aggreg join to display total of sold quantity |
812 | 812 |
# onhand - as above, but masking the simple itemstatus results (doh!) |
... | ... | |
814 | 814 |
# l_serialnumber - belonges to serialnumber filter |
815 | 815 |
# l_deliverydate - displays deliverydate is sold etc. flags are active |
816 | 816 |
# |
817 |
# not working:
|
|
817 |
# not working: |
|
818 | 818 |
# l_soldtotal - aggreg join to display total of sold quantity |
819 | 819 |
# onhand - as above, but masking the simple itemstatus results (doh!) |
820 | 820 |
# masking of onhand in bsooqr mode - ToDO: fixme |
... | ... | |
852 | 852 |
my %joins = ( |
853 | 853 |
partsgroup => 'LEFT JOIN partsgroup pg ON p.partsgroup_id = pg.id', |
854 | 854 |
makemodel => 'LEFT JOIN makemodel mm ON mm.parts_id = p.id', |
855 |
invoice_oi =>
|
|
856 |
q|LEFT JOIN (
|
|
857 |
SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, assemblyitem, 'invoice' AS ioi FROM invoice UNION
|
|
858 |
SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, 'orderitems' AS ioi FROM orderitems
|
|
855 |
invoice_oi => |
|
856 |
q|LEFT JOIN ( |
|
857 |
SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, assemblyitem, 'invoice' AS ioi FROM invoice UNION |
|
858 |
SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, 'orderitems' AS ioi FROM orderitems |
|
859 | 859 |
) AS ioi ON ioi.parts_id = p.id|, |
860 |
apoe =>
|
|
861 |
q|LEFT JOIN (
|
|
860 |
apoe => |
|
861 |
q|LEFT JOIN ( |
|
862 | 862 |
SELECT id, transdate, 'ir' AS module, ordnumber, quonumber, invnumber, FALSE AS quotation, NULL AS customer_id, vendor_id, NULL AS deliverydate FROM ap UNION |
863 | 863 |
SELECT id, transdate, 'is' AS module, ordnumber, quonumber, invnumber, FALSE AS quotation, customer_id, NULL AS vendor_id, deliverydate FROM ar UNION |
864 | 864 |
SELECT id, transdate, 'oe' AS module, ordnumber, quonumber, NULL AS invnumber, quotation, customer_id, vendor_id, NULL AS deliverydate FROM oe |
865 | 865 |
) AS apoe ON ioi.trans_id = apoe.id|, |
866 | 866 |
cv => |
867 |
q|LEFT JOIN (
|
|
868 |
SELECT id, name, 'customer' AS cv FROM customer UNION
|
|
869 |
SELECT id, name, 'vendor' AS cv FROM vendor
|
|
867 |
q|LEFT JOIN ( |
|
868 |
SELECT id, name, 'customer' AS cv FROM customer UNION |
|
869 |
SELECT id, name, 'vendor' AS cv FROM vendor |
|
870 | 870 |
) AS cv ON cv.id = apoe.customer_id OR cv.id = apoe.vendor_id|, |
871 | 871 |
); |
872 | 872 |
my @join_order = qw(partsgroup makemodel invoice_oi apoe cv); |
... | ... | |
892 | 892 |
foreach (@simple_filters, @makemodel_filters, @invoice_oi_filters) { |
893 | 893 |
next unless $form->{$_}; |
894 | 894 |
$form->{"l_$_"} = '1'; # show the column |
895 |
push @where_tokens, "$_ ILIKE ?";
|
|
895 |
push @where_tokens, "$_ ILIKE ?"; |
|
896 | 896 |
push @bind_vars, "%$form->{$_}%"; |
897 | 897 |
} |
898 | 898 |
|
... | ... | |
909 | 909 |
} |
910 | 910 |
|
911 | 911 |
for ($form->{itemstatus}) { |
912 |
push @where_tokens, 'p.id NOT IN
|
|
913 |
(SELECT DISTINCT parts_id FROM invoice UNION
|
|
914 |
SELECT DISTINCT parts_id FROM assembly UNION
|
|
912 |
push @where_tokens, 'p.id NOT IN |
|
913 |
(SELECT DISTINCT parts_id FROM invoice UNION |
|
914 |
SELECT DISTINCT parts_id FROM assembly UNION |
|
915 | 915 |
SELECT DISTINCT parts_id FROM orderitems)' if /orphaned/; |
916 | 916 |
push @where_tokens, 'p.onhand = 0' if /orphaned/; |
917 | 917 |
push @where_tokens, 'NOT p.obsolete' if /active/; |
918 | 918 |
push @where_tokens, ' p.obsolete', if /obsolete/; |
919 | 919 |
push @where_tokens, 'p.onhand > 0', if /onhand/; |
920 | 920 |
push @where_tokens, 'p.onhand < p.rop', if /short/; |
921 |
}
|
|
921 |
} |
|
922 | 922 |
|
923 | 923 |
|
924 | 924 |
my @sort_cols = (@simple_filters, qw(id bin priceupdate onhand invnumber ordnumber quonumber name serialnumber soldtotal deliverydate)); |
... | ... | |
928 | 928 |
my $limit_clause = " LIMIT 100" if $form->{top100}; |
929 | 929 |
|
930 | 930 |
#=== joins and complicated filters ========# |
931 |
|
|
931 |
|
|
932 | 932 |
my $bsooqr = $form->{bought} || $form->{sold} |
933 | 933 |
|| $form->{ordered} || $form->{onorder} |
934 | 934 |
|| $form->{quoted} || $form->{rfq}; |
935 |
|
|
935 |
|
|
936 | 936 |
my @bsooqr; |
937 | 937 |
push @select_tokens, @qsooqr_flags if $bsooqr; |
938 | 938 |
push @select_tokens, @deliverydate_flags if $bsooqr && $form->{l_deliverydate}; |
... | ... | |
973 | 973 |
#============= build query ================# |
974 | 974 |
|
975 | 975 |
my %table_prefix = ( |
976 |
deliverydate => 'apoe.', serialnumber => 'ioi.',
|
|
977 |
transdate => 'apoe.', trans_id => 'ioi.',
|
|
978 |
module => 'apoe.', name => 'cv.',
|
|
979 |
ordnumber => 'apoe.', make => 'mm.',
|
|
980 |
quonumber => 'apoe.', model => 'mm.',
|
|
976 |
deliverydate => 'apoe.', serialnumber => 'ioi.', |
|
977 |
transdate => 'apoe.', trans_id => 'ioi.', |
|
978 |
module => 'apoe.', name => 'cv.', |
|
979 |
ordnumber => 'apoe.', make => 'mm.', |
|
980 |
quonumber => 'apoe.', model => 'mm.', |
|
981 | 981 |
invnumber => 'apoe.', partsgroup => 'pg.', |
982 | 982 |
'SUM(ioi.qty) AS soldtotal' => ' ', |
983 | 983 |
); |
984 |
|
|
984 |
|
|
985 | 985 |
map { $table_prefix{$_} = 'ioi.' } qw(description serialnumber qty unit) if $joins_needed{invoice_oi}; |
986 | 986 |
|
987 | 987 |
my $select_clause = join ', ', map { ($table_prefix{$_} || "p.") . $_ } @select_tokens; |
... | ... | |
1092 | 1092 |
## if ($form->{l_soldtotal}) { |
1093 | 1093 |
## $form->{soldtotal} = 'soldtotal'; |
1094 | 1094 |
## $query = |
1095 |
## qq|SELECT p.id, p.partnumber, p.description, p.onhand, p.unit,
|
|
1096 |
## p.bin, p.sellprice, p.listprice, p.lastcost,
|
|
1097 |
## p.priceupdate, pg.partsgroup,sum(i.qty) AS soldtotal
|
|
1098 |
## FROM parts p
|
|
1095 |
## qq|SELECT p.id, p.partnumber, p.description, p.onhand, p.unit, |
|
1096 |
## p.bin, p.sellprice, p.listprice, p.lastcost, |
|
1097 |
## p.priceupdate, pg.partsgroup,sum(i.qty) AS soldtotal |
|
1098 |
## FROM parts p |
|
1099 | 1099 |
## LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id), invoice i |
1100 | 1100 |
## WHERE $where |
1101 | 1101 |
## $group |
Auch abrufbar als: Unified diff
Kosmetik: trailing whitespace entfernt.