haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
100
101
102
103
104
105
106
107
108
109
110
import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
import { ListBase } from '../../libappbase/listbase';
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component';
import { DialogInventoryCost } from '../dialogs/dialog.inventorycost';
import { asyncEvery } from '../../libappbase/utils';
import { CheckboxBase } from '../../libappbase/checkboxbase';
import { QContextMenu } from '../../e2elib/lib/api/pageobjects/qcontextmenu.component';
 
/**
 * Inventory Cost PISP form.
 */
export class FormInventoryCosts extends Form {
  public lstAccountCosts = new ListAccountCosts();
  public cbFilterByAccounts = new CheckboxBase('cbFilterByAccounts');
 
  public constructor() {
    super('FormInventoryCosts');
  }
 
  /**
   * Toggle filter by account on or off
   *
   * @param isToggleOn Indicate to toggle on or off
   */
  public async toggleFilterByAccount(isToggleOn: boolean): Promise<void> {
    await this.cbFilterByAccounts.toggle(isToggleOn);
  }
}
 
/**
 * Inventory PISP list in Inventory Cost PISP form.
 */
export class ListAccountCosts extends ListBase {
  public dlgInventoryCost = new DialogInventoryCost();
  public cmMenu = new QContextMenu('lsContextMenuAccCosts');
 
  public constructor() {
    super('lsAccountCosts');
  }
 
  /**
   * Get inventory cost in list by product name
   *
   * @param product Product name
   * @returns ListRow that match the product name
   */
  public async getInventoryCostByName(product: string): Promise<ListRow> {
    return this.getRowByValue([{ columnID: ListColumnAccountCosts.Product, value: product }]);
  }
 
  /**
   * Open create inventory cost dialog by context menu, field in value and confirm the dialog
   *
   * @param account Account field value
   * @param costDriver Cost driver field value
   * @param product Product field value
   * @param stockingPoint Stocking point field value
   * @param startDate Start date field value
   * @param cost Cost field value
   * @returns Boolean indicates whether the create action is successful or not
   */
  public async createNewInventoryCost(account: string, costDriver: string, product: string, stockingPoint: string, startDate: Date, cost: number): Promise<boolean> {
    await this.rightClick(undefined, this.cmMenu, 'MenuCreate');
    await this.dlgInventoryCost.waitUntilPresent();
    await this.dlgInventoryCost.updateDialog(account, costDriver, product, stockingPoint, startDate, cost);
    return this.dlgInventoryCost.closeDialog();
  }
 
  /**
   * Verify if all rows has correct value in the column
   *
   * @param rows ListRows to verify
   * @param columnName Name of the column to verify
   * @param value Expected value of the column
   */
  public async matchColumnValueFromRows(rows: ListRow[], columnName: string, value: string): Promise<boolean> {
    const cellValues = await this.getCellValueFromRow(columnName, rows);
    const result = await asyncEvery(cellValues, async (cellValue: string) => Promise.resolve(cellValue === value));
    return result;
  }
 
  /**
   * Find inventory cost by value from the list
   *
   * @param product Product column value
   * @param stockingPoint Stocking point column value
   * @param account Account column value
   * @param costDriver Cost driver column value
   * @param cost Cost column value
   */
  public async findInventoryCost(product: string, stockingPoint: string, account: string, costDriver: string, cost: number): Promise<ListRow | undefined> {
    const result = await this.getRowByValue([
      { columnID: ListColumnAccountCosts.Product, value: product },
      { columnID: ListColumnAccountCosts.StockingPoint, value: stockingPoint },
      { columnID: ListColumnAccountCosts.Account, value: account },
      { columnID: ListColumnAccountCosts.CostDriver, value: costDriver },
      { columnID: ListColumnAccountCosts.Cost, value: cost.toString() },
    ]).catch(() => undefined);
 
    return result;
  }
}
 
export enum ListColumnAccountCosts {
  Product = 'Product',
  StockingPoint = 'Stocking point',
  Account = 'Account',
  CostDriver = 'Cost driver',
  Cost = 'Cost',
}