-
Notifications
You must be signed in to change notification settings - Fork 1
/
process-invoice.sh
executable file
·100 lines (68 loc) · 3.06 KB
/
process-invoice.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -e
ICOPROVIDER=`cat "$1" | ./find-ico.sh | ./validate-ico.sh | head -n 1`
if [ -z $ICOPROVIDER ]
then
echo "I guess it is not an invoice"
exit 1
fi
ICOCUSTOMER=`cat "$1" | sed -e "s/$ICOPROVIDER//" | ./find-ico.sh | ./validate-ico.sh | head -n 1`
echo ICOPROVIDER=$ICOPROVIDER
echo ICOCUSTOMER=$ICOCUSTOMER
DICPROVIDER=`cat "$1" | ./find-dic.sh | ./validate-dic.sh | head -n 1`
DICCUSTOMER=`cat "$1" | sed -e "s/$DICPROVIDER//" | ./find-dic.sh | ./validate-dic.sh | head -n 1`
echo DICPROVIDER=$DICPROVIDER
echo DICCUSTOMER=$DICCUSTOMER
EUVATIDPROVIDER=`cat "$1" | ./find-euvatid.sh | ./validate-euvatid.sh | head -n 1`
EUVATIDCUSTOMER=`cat "$1" | sed -e "s/$EUVATIDPROVIDER//" | ./find-euvatid.sh | ./validate-euvatid.sh | head -n 1`
echo EUVATIDPROVIDER=$EUVATIDPROVIDER
echo EUVATIDCUSTOMER=$EUVATIDCUSTOMER
INVOICENUMBER=`grep -iE "fakt[uú]ra" "$1" | perl -p -e "s/$EUVATIDPROVIDER//;s/$ICOPROVIDER//;s/$DICPROVIDER//;s/$EUVATIDCUSTOMER//;s/$ICOCUSTOMER//;s/$DICCUSTOMER//;" | grep -o -E "(\d+/\d+)|\d{2,}" | head -n 1`
if [ -z "$INVOICENUMBER" ]
then
INVOICENUMBER=`cat "$1" | perl -p -e "s/$EUVATIDPROVIDER//;s/$ICOPROVIDER//;s/$DICPROVIDER//;s/$EUVATIDCUSTOMER//;s/$ICOCUSTOMER//;s/$DICCUSTOMER//;" | grep -o -E "\d{2,}" | head -n 1`
fi
echo INVOICENUMBER=$INVOICENUMBER
VS=`grep -oi "Variabilný symbol.*" "$1" | perl -p -e "s/$EUVATIDPROVIDER//;s/$ICOPROVIDER//;s/$DICPROVIDER//;s/$EUVATIDCUSTOMER//;s/$ICOCUSTOMER//;s/$DICCUSTOMER//;" | grep -o -E "\d{2,}" | head -n 1`
if [ -z "$VS" ]
then
VS=`grep -iEo "[^\w]VS:.*" "$1" | perl -p -e "s/$EUVATIDPROVIDER//;s/$ICOPROVIDER//;s/$DICPROVIDER//;s/$EUVATIDCUSTOMER//;s/$ICOCUSTOMER//;s/$DICCUSTOMER//;" | grep -o -E "\d{2,}" | head -n 1`
fi
#if [ -z "$VS" ]
#then
# VS=$INVOICENUMBER
#fi
echo -n "VARIABLESYMBOL=$VS"
if [ "$INVOICENUMBER" = "$VS" ]
then
echo " ok "
else
echo " !!! "
fi
DATEINVOICE=`grep -iE "Dátum (vystavenia|vyhotovenia)" "$1" | grep -oE "\d{2}\. ?\d{1,2}\. ?20\d{2}" | head -n 1`
DATEPROVIDED=`grep -iE "Dátum dodania" "$1" | grep -oE "\d{2}\. ?\d{1,2}\. ?20\d{2}" | head -n 1`
DATEPAYMENT=`grep -iE "splatnos" "$1" | grep -oE "\d{2}\. ?\d{1,2}\. ?20\d{2}" | head -n 1`
echo DATEINVOICE=$DATEINVOICE
echo DATEPROVIDED=$DATEPROVIDED
echo DATEPAYMENT=$DATEPAYMENT
#grep -E "^.*\d{2}\.\d{1,2}\.20\d{2}" "$1"
SUM=`grep -iE "EUR|€" "$1" | grep -vE "\d{2}\.\d{1,2}\.20\d{2}" | ./find-money.pl | sort -gr | head -n 1`
if [ -z "$SUM" ]
then
SUM=`cat "$1" | grep -vE "\d{2}\.\d{1,2}\.20\d{2}" | ./find-money.pl | sort -gr | head -n 1`
fi
echo SUM=$SUM
IBAN=`grep -o -w -E "[A-Z]{2}\d{22}" "$1"`
echo IBAN=$IBAN
echo "insert into faktury set ProviderID='"$ICOPROVIDER"',CustomerID='"$ICOCUSTOMER"',\
ProviderTAXID='"$DICPROVIDER"',\
CustomerTAXID='"$DICCUSTOMER"',\
ProviderEUVATID='"$EUVATIDPROVIDER"',\
CustomerEUVATID='"$EUVATIDCUSTOMER"',\
InvoiceNumber='"$INVOICENUMBER"',\
VariableSymbol='"$VS"',\
DateInvoice=STR_TO_DATE('"$DATEINVOICE"','%d.%m.%Y'),\
DateProvided=STR_TO_DATE('"$DATEPROVIDED"','%d.%m.%Y'),\
DatePayment=STR_TO_DATE('"$DATEPAYMENT"','%d.%m.%Y'),\
Total='"$SUM"',\
IBAN='"$IBAN"'"