@@ -37,33 +37,55 @@ export class PurchasingDataSource implements IPurchasingDataSource {
37
37
throw new Error ( "Method not implemented." ) ;
38
38
}
39
39
40
- async selectAll ( conf : Pick < ParamsEntity , 'limit' | 'offset' | 'search' | 'kontrak_type' | 'pks_type' | 'stockpile_id' > ) : Promise < PurchasingEntity [ ] > {
40
+ async selectAll ( conf : Pick < ParamsEntity , 'limit' | 'offset' | 'search' | 'kontrak_type' | 'pks_type' | 'stockpile_id' | 'final_status' > ) : Promise < PurchasingEntity [ ] > {
41
41
let limit = ''
42
42
let where = ``
43
+ let orderBy = `, p.purchasing_id DESC`
43
44
44
45
if ( conf ! . pks_type == 'PKS-Contract' ) {
45
46
where = `where p.type = 1 and p.contract_type = 1`
46
47
if ( conf ! . stockpile_id ) {
47
48
where += ` and s.stockpile_id = ${ conf ! . stockpile_id } `
48
49
}
49
50
if ( conf ! . search ) where += ` and (v.vendor_name LIKE '%${ conf ! . search } %' or s.stockpile_name LIKE '%${ conf ! . search } %')`
51
+ if ( conf ! . final_status ) {
52
+ where += ` and popks.final_status = ${ conf ?. final_status } `
53
+ orderBy = conf ! . final_status == 2 || conf ! . final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
54
+ }
50
55
} else if ( conf ! . pks_type == 'PKS-Curah' ) {
51
56
where = `where p.type = 2 and p.contract_type = 1`
52
57
if ( conf ! . stockpile_id ) {
53
58
where += ` and s.stockpile_id = ${ conf ! . stockpile_id } `
54
59
}
55
60
if ( conf ! . search ) where += ` and (v.vendor_name LIKE '%${ conf ! . search } %' or s.stockpile_name LIKE '%${ conf ! . search } %')`
61
+ if ( conf ! . final_status ) {
62
+ where += ` and popks.final_status = ${ conf ?. final_status } `
63
+ orderBy = conf ! . final_status == 2 || conf ! . final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
64
+ }
56
65
} else if ( conf ! . kontrak_type == 'PKS-Spb' ) {
57
66
where = `where (p.type = 2 or p.type = 1) and p.contract_type = 2`
58
67
if ( conf ! . stockpile_id ) {
59
68
where += ` and s.stockpile_id = ${ conf ! . stockpile_id } `
60
69
}
61
70
if ( conf ! . search ) where += ` and (v.vendor_name LIKE '%${ conf ! . search } %' or s.stockpile_name LIKE '%${ conf ! . search } %')`
71
+ if ( conf ! . final_status ) {
72
+ where += ` and popks.final_status = ${ conf ?. final_status } `
73
+ orderBy = conf ! . final_status == 2 || conf ! . final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
74
+ }
62
75
} else if ( conf ! . stockpile_id ) {
63
76
where = `where s.stockpile_id = ${ conf ! . stockpile_id } `
64
77
if ( conf ! . search ) where += ` and (v.vendor_name LIKE '%${ conf ! . search } %' or s.stockpile_name LIKE '%${ conf ! . search } %')`
65
- } else if ( conf ! . search ) where = `where (v.vendor_name LIKE '%${ conf ! . search } %' or s.stockpile_name LIKE '%${ conf ! . search } %')`
66
-
78
+ if ( conf ! . final_status ) {
79
+ where += ` and popks.final_status = ${ conf ?. final_status } `
80
+ orderBy = conf ! . final_status == 2 || conf ! . final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
81
+ }
82
+ } else if ( conf ! . search ) {
83
+ where = `where (v.vendor_name LIKE '%${ conf ! . search } %' or s.stockpile_name LIKE '%${ conf ! . search } %')`
84
+ if ( conf ! . final_status ) {
85
+ where += ` and popks.final_status = ${ conf ?. final_status } `
86
+ orderBy = conf ! . final_status == 2 || conf ! . final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
87
+ }
88
+ }
67
89
if ( conf ! . offset || conf . limit ) limit = `limit ${ conf . offset } , ${ conf . limit } `
68
90
69
91
const [ rows , fields ] = await this . dql . dataQueryLanguage (
@@ -104,7 +126,7 @@ export class PurchasingDataSource implements IPurchasingDataSource {
104
126
LEFT JOIN ${ process . env . TABLE_POPKS } popks
105
127
ON popks.purchasing_id = p.purchasing_id
106
128
${ where }
107
- ORDER BY popks.final_status DESC, p.purchasing_id DESC
129
+ ORDER BY popks.final_status DESC ${ orderBy }
108
130
${ limit } ;
109
131
` , [ ]
110
132
)
@@ -186,6 +208,16 @@ export class PurchasingDataSource implements IPurchasingDataSource {
186
208
return res
187
209
}
188
210
211
+ async updateFileSpb ( id ?: number | undefined , data ?: Pick < PurchasingEntity , "import2" | "approval_file" | "upload_file1" | "upload_file2" | "upload_file3" | "upload_file4" | "import2_date" > | undefined ) : Promise < any > {
212
+ const res = await this . dml . dataManipulation (
213
+ `update file purchasing, spb` ,
214
+ `update ${ process . env . TABLE_PURCHASING } set import2 = ?, approval_file = ?, upload_file1 = ?, upload_file2 = ?, upload_file3 = ?, upload_file4 = ?, import2_date = ? where purchasing_id = ? and status = ?` ,
215
+ [ data ?. import2 , data ?. approval_file , data ?. upload_file1 , data ?. upload_file2 , data ?. upload_file3 , data ?. upload_file4 , data ?. import2_date , id ! , 2 ]
216
+ )
217
+
218
+ return res
219
+ }
220
+
189
221
async delete ( id ?: number | undefined ) : Promise < any > {
190
222
const res = await this . dml . dataManipulation (
191
223
`delete purchasing` ,
0 commit comments