proflores-db-model 0.2.52 → 0.2.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/entities/ExpenseDetail.d.ts +6 -0
  2. package/dist/entities/ExpenseDetail.js +19 -1
  3. package/dist/entities/ExpenseTransaction.d.ts +2 -0
  4. package/dist/entities/ExpenseTransaction.js +11 -1
  5. package/dist/entities/Income.d.ts +29 -0
  6. package/dist/entities/Income.js +121 -0
  7. package/dist/entities/InventoryMovement.d.ts +2 -0
  8. package/dist/entities/InventoryMovement.js +7 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +4 -1
  11. package/dist/models/apu/Budget.d.ts +4 -0
  12. package/dist/models/apu/Budget.js +10 -0
  13. package/dist/models/production/CropActivity.d.ts +20 -0
  14. package/dist/models/production/CropActivity.js +85 -0
  15. package/dist/models/production/CropExpense.d.ts +22 -0
  16. package/dist/models/production/CropExpense.js +93 -0
  17. package/dist/models/production/CropLot.d.ts +33 -0
  18. package/dist/models/production/CropLot.js +132 -0
  19. package/dist/models/production/CropStage.d.ts +13 -0
  20. package/dist/models/production/CropStage.js +58 -0
  21. package/dist/models/production/CropStageImage.d.ts +9 -0
  22. package/dist/models/production/CropStageImage.js +44 -0
  23. package/dist/models/production/GrowthArea.d.ts +13 -0
  24. package/dist/models/production/GrowthArea.js +55 -0
  25. package/dist/models/production/Harvest.d.ts +16 -0
  26. package/dist/models/production/Harvest.js +70 -0
  27. package/dist/models/production/ProductionSeason.d.ts +11 -0
  28. package/dist/models/production/ProductionSeason.js +49 -0
  29. package/dist/models/production/index.d.ts +8 -0
  30. package/dist/models/production/index.js +20 -0
  31. package/dist/types/CropActivityType.d.ts +12 -0
  32. package/dist/types/CropActivityType.js +16 -0
  33. package/dist/types/CropLotStatus.d.ts +10 -0
  34. package/dist/types/CropLotStatus.js +14 -0
  35. package/dist/types/GrowthStage.d.ts +10 -0
  36. package/dist/types/GrowthStage.js +14 -0
  37. package/dist/types/IncomeStatus.d.ts +5 -0
  38. package/dist/types/IncomeStatus.js +9 -0
  39. package/dist/types/IncomeType.d.ts +6 -0
  40. package/dist/types/IncomeType.js +10 -0
  41. package/dist/types/MovementType.d.ts +2 -1
  42. package/dist/types/MovementType.js +1 -0
  43. package/dist/types/QualityGrade.d.ts +6 -0
  44. package/dist/types/QualityGrade.js +10 -0
  45. package/dist/types/index.d.ts +6 -0
  46. package/dist/types/index.js +15 -1
  47. package/package.json +1 -1
  48. package/src/entities/ExpenseDetail.ts +16 -1
  49. package/src/entities/ExpenseTransaction.ts +12 -2
  50. package/src/entities/Income.ts +99 -0
  51. package/src/entities/InventoryMovement.ts +7 -1
  52. package/src/index.ts +2 -0
  53. package/src/models/apu/Budget.ts +8 -0
  54. package/src/models/production/CropActivity.ts +68 -0
  55. package/src/models/production/CropExpense.ts +74 -0
  56. package/src/models/production/CropLot.ts +106 -0
  57. package/src/models/production/CropStage.ts +45 -0
  58. package/src/models/production/CropStageImage.ts +32 -0
  59. package/src/models/production/GrowthArea.ts +41 -0
  60. package/src/models/production/Harvest.ts +56 -0
  61. package/src/models/production/ProductionSeason.ts +34 -0
  62. package/src/models/production/index.ts +9 -0
  63. package/src/types/CropActivityType.ts +12 -0
  64. package/src/types/CropLotStatus.ts +10 -0
  65. package/src/types/GrowthStage.ts +10 -0
  66. package/src/types/IncomeStatus.ts +5 -0
  67. package/src/types/IncomeType.ts +6 -0
  68. package/src/types/MovementType.ts +5 -4
  69. package/src/types/QualityGrade.ts +6 -0
  70. package/src/types/index.ts +11 -1
@@ -0,0 +1,6 @@
1
+ export declare enum QualityGrade {
2
+ PREMIUM = "PREMIUM",
3
+ STANDARD = "STANDARD",
4
+ ECONOMY = "ECONOMY",
5
+ REJECTED = "REJECTED"
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QualityGrade = void 0;
4
+ var QualityGrade;
5
+ (function (QualityGrade) {
6
+ QualityGrade["PREMIUM"] = "PREMIUM";
7
+ QualityGrade["STANDARD"] = "STANDARD";
8
+ QualityGrade["ECONOMY"] = "ECONOMY";
9
+ QualityGrade["REJECTED"] = "REJECTED";
10
+ })(QualityGrade || (exports.QualityGrade = QualityGrade = {}));
@@ -3,3 +3,9 @@ export { ExpenseDetailType } from "./ExpenseDetailType";
3
3
  export { ExpenseTypeType } from "./ExpenseTypeType";
4
4
  export { ProjectOrderType } from "./ProjectOrderType";
5
5
  export { MovementType } from "./MovementType";
6
+ export { CropLotStatus } from "./CropLotStatus";
7
+ export { GrowthStage } from "./GrowthStage";
8
+ export { CropActivityType } from "./CropActivityType";
9
+ export { QualityGrade } from "./QualityGrade";
10
+ export { IncomeType } from "./IncomeType";
11
+ export { IncomeStatus } from "./IncomeStatus";
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MovementType = void 0;
3
+ exports.IncomeStatus = exports.IncomeType = exports.QualityGrade = exports.CropActivityType = exports.GrowthStage = exports.CropLotStatus = exports.MovementType = void 0;
4
4
  var MovementType_1 = require("./MovementType");
5
5
  Object.defineProperty(exports, "MovementType", { enumerable: true, get: function () { return MovementType_1.MovementType; } });
6
+ // Production enums
7
+ var CropLotStatus_1 = require("./CropLotStatus");
8
+ Object.defineProperty(exports, "CropLotStatus", { enumerable: true, get: function () { return CropLotStatus_1.CropLotStatus; } });
9
+ var GrowthStage_1 = require("./GrowthStage");
10
+ Object.defineProperty(exports, "GrowthStage", { enumerable: true, get: function () { return GrowthStage_1.GrowthStage; } });
11
+ var CropActivityType_1 = require("./CropActivityType");
12
+ Object.defineProperty(exports, "CropActivityType", { enumerable: true, get: function () { return CropActivityType_1.CropActivityType; } });
13
+ var QualityGrade_1 = require("./QualityGrade");
14
+ Object.defineProperty(exports, "QualityGrade", { enumerable: true, get: function () { return QualityGrade_1.QualityGrade; } });
15
+ // Income enums
16
+ var IncomeType_1 = require("./IncomeType");
17
+ Object.defineProperty(exports, "IncomeType", { enumerable: true, get: function () { return IncomeType_1.IncomeType; } });
18
+ var IncomeStatus_1 = require("./IncomeStatus");
19
+ Object.defineProperty(exports, "IncomeStatus", { enumerable: true, get: function () { return IncomeStatus_1.IncomeStatus; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proflores-db-model",
3
- "version": "0.2.52",
3
+ "version": "0.2.53",
4
4
  "description": "Data model for managing expenses and transactions for Proflores nursery business",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,6 +9,9 @@ import {
9
9
  import { ExpenseTransaction } from "./ExpenseTransaction";
10
10
  import { Inventory } from "./Inventory";
11
11
  import { ProjectOrder } from "./ProjectOrder";
12
+ import { Budget } from "../models/apu/Budget";
13
+ import { CropLot } from "../models/production/CropLot";
14
+ import { CropActivity } from "../models/production/CropActivity";
12
15
 
13
16
  @Entity()
14
17
  export class ExpenseDetail implements ObjectLiteral {
@@ -44,7 +47,19 @@ export class ExpenseDetail implements ObjectLiteral {
44
47
  @Column("boolean", { default: true })
45
48
  isActive!: boolean;
46
49
 
47
- @ManyToOne(() => ProjectOrder, { nullable: false })
50
+ @ManyToOne(() => ProjectOrder, { nullable: true })
48
51
  @JoinColumn({ name: "projectId" })
49
52
  projectOrder?: ProjectOrder;
53
+
54
+ @ManyToOne(() => Budget, { nullable: true, onDelete: "SET NULL" })
55
+ @JoinColumn({ name: "idBudget" })
56
+ budget?: Budget | null;
57
+
58
+ @ManyToOne(() => CropLot, { nullable: true, onDelete: "SET NULL" })
59
+ @JoinColumn({ name: "idCropLot" })
60
+ cropLot?: CropLot | null;
61
+
62
+ @ManyToOne(() => CropActivity, { nullable: true, onDelete: "SET NULL" })
63
+ @JoinColumn({ name: "idCropActivity" })
64
+ cropActivity?: CropActivity | null;
50
65
  }
@@ -7,13 +7,16 @@ import {
7
7
  JoinColumn,
8
8
  OneToMany,
9
9
  ObjectLiteral,
10
- OneToOne
10
+ OneToOne,
11
+ Index,
11
12
  } from "typeorm";
12
13
  import { ExpenseType } from "./ExpenseType";
13
14
  import { ExpenseDetail } from "./ExpenseDetail";
14
15
  import { TransactionBank } from "./Bank/TransactionBank";
16
+ import { Budget } from "../models/apu/Budget";
15
17
 
16
18
  @Entity()
19
+ @Index(["budget"])
17
20
  export class ExpenseTransaction implements ObjectLiteral {
18
21
  @PrimaryGeneratedColumn("increment")
19
22
  expenseTransactionId!: number;
@@ -46,7 +49,14 @@ export class ExpenseTransaction implements ObjectLiteral {
46
49
  expenseDetails?: ExpenseDetail[];
47
50
 
48
51
  @OneToOne(() => TransactionBank, (transactionBank) => transactionBank.expenseTransaction, {
49
- nullable: true,
52
+ nullable: true,
50
53
  })
51
54
  transactionBank?: TransactionBank;
55
+
56
+ @ManyToOne(() => Budget, (budget) => budget.expenses, {
57
+ nullable: true,
58
+ onDelete: "SET NULL",
59
+ })
60
+ @JoinColumn({ name: "idBudget" })
61
+ budget?: Budget | null;
52
62
  }
@@ -0,0 +1,99 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ OneToOne,
7
+ JoinColumn,
8
+ ObjectLiteral,
9
+ Index,
10
+ CreateDateColumn,
11
+ UpdateDateColumn,
12
+ } from "typeorm";
13
+ import { Budget } from "../models/apu/Budget";
14
+ import { Payment } from "./Payment";
15
+ import { CropLot } from "../models/production/CropLot";
16
+ import { Client } from "../models/apu/Client";
17
+ import { Inventory } from "./Inventory";
18
+ import { TransactionBank } from "./Bank/TransactionBank";
19
+ import { IncomeType } from "../types/IncomeType";
20
+ import { IncomeStatus } from "../types/IncomeStatus";
21
+
22
+ @Entity("incomes")
23
+ @Index(["incomeDate"])
24
+ @Index(["incomeType"])
25
+ @Index(["status"])
26
+ @Index(["budget"])
27
+ @Index(["cropLot"])
28
+ export class Income implements ObjectLiteral {
29
+ @PrimaryGeneratedColumn("increment")
30
+ idIncome!: number;
31
+
32
+ @Column({
33
+ type: "enum",
34
+ enum: IncomeType,
35
+ default: IncomeType.OTHER,
36
+ })
37
+ incomeType!: IncomeType;
38
+
39
+ @Column("decimal", { precision: 14, scale: 2, nullable: false })
40
+ amount!: number;
41
+
42
+ @Column("date", { nullable: false })
43
+ incomeDate!: Date;
44
+
45
+ @Column("text", { nullable: true })
46
+ description?: string | null;
47
+
48
+ @Column({
49
+ type: "enum",
50
+ enum: IncomeStatus,
51
+ default: IncomeStatus.PENDING,
52
+ })
53
+ status!: IncomeStatus;
54
+
55
+ @ManyToOne(() => Budget, (budget) => budget.incomes, {
56
+ nullable: true,
57
+ onDelete: "SET NULL",
58
+ })
59
+ @JoinColumn({ name: "idBudget" })
60
+ budget?: Budget | null;
61
+
62
+ @ManyToOne(() => Payment, { nullable: true, onDelete: "SET NULL" })
63
+ @JoinColumn({ name: "idPayment" })
64
+ payment?: Payment | null;
65
+
66
+ @ManyToOne(() => CropLot, { nullable: true, onDelete: "SET NULL" })
67
+ @JoinColumn({ name: "idCropLot" })
68
+ cropLot?: CropLot | null;
69
+
70
+ @ManyToOne(() => Client, { nullable: true, onDelete: "SET NULL" })
71
+ @JoinColumn({ name: "idClient" })
72
+ client?: Client | null;
73
+
74
+ @ManyToOne(() => Inventory, { nullable: true, onDelete: "SET NULL" })
75
+ @JoinColumn({ name: "idInventory" })
76
+ inventory?: Inventory | null;
77
+
78
+ @Column("decimal", { precision: 12, scale: 4, nullable: true })
79
+ quantity?: number | null;
80
+
81
+ @Column("decimal", { precision: 14, scale: 4, nullable: true })
82
+ unitPrice?: number | null;
83
+
84
+ @Column("varchar", { length: 255, nullable: true })
85
+ invoiceUuid?: string | null;
86
+
87
+ @OneToOne(() => TransactionBank, { nullable: true, cascade: true })
88
+ @JoinColumn({ name: "idTransactionBank" })
89
+ transactionBank?: TransactionBank | null;
90
+
91
+ @Column("text", { nullable: true })
92
+ notes?: string | null;
93
+
94
+ @CreateDateColumn({ type: "timestamp" })
95
+ createdAt!: Date;
96
+
97
+ @UpdateDateColumn({ type: "timestamp" })
98
+ updatedAt!: Date;
99
+ }
@@ -3,6 +3,7 @@ import {
3
3
  PrimaryGeneratedColumn,
4
4
  Column,
5
5
  ManyToOne,
6
+ OneToOne,
6
7
  JoinColumn,
7
8
  CreateDateColumn,
8
9
  UpdateDateColumn,
@@ -10,6 +11,7 @@ import {
10
11
  } from "typeorm";
11
12
  import { Inventory } from "./Inventory";
12
13
  import { MovementType } from "../types/MovementType";
14
+ import { Harvest } from "../models/production/Harvest";
13
15
  @Entity("inventory_movement")
14
16
  export class InventoryMovement implements ObjectLiteral {
15
17
  @PrimaryGeneratedColumn("increment")
@@ -47,6 +49,10 @@ import {
47
49
 
48
50
  @Column("varchar", { length: 50, nullable: true })
49
51
  referenceModule?: string;
50
-
52
+
53
+ @OneToOne(() => Harvest, (harvest) => harvest.inventoryMovement, {
54
+ nullable: true,
55
+ })
56
+ harvest?: Harvest | null;
51
57
  }
52
58
 
package/src/index.ts CHANGED
@@ -21,7 +21,9 @@ export { SupplierImage } from "./entities/SupplierImage";
21
21
  export { InventoryImage } from "./entities/InventoryImage";
22
22
  export { Payment } from "./entities/Payment";
23
23
  export { PaymentCfdi } from "./entities/PaymentCfdi";
24
+ export { Income } from "./entities/Income";
24
25
 
25
26
  export * from "./types";
26
27
  export * from "./models/technical-sheet";
27
28
  export * from "./models/apu";
29
+ export * from "./models/production";
@@ -6,6 +6,8 @@ import { Project } from "./Project";
6
6
  import { BudgetItem } from "./BudgetItem";
7
7
  import { BudgetCancellationFolio } from "./BudgetCancellationFolio";
8
8
  import { Payment } from "../../entities/Payment";
9
+ import { ExpenseTransaction } from "../../entities/ExpenseTransaction";
10
+ import { Income } from "../../entities/Income";
9
11
 
10
12
  @Entity("budgets")
11
13
  @Index(["project"])
@@ -55,4 +57,10 @@ export class Budget implements ObjectLiteral {
55
57
 
56
58
  @OneToMany(() => Payment, (payment) => payment.budget)
57
59
  payments?: Payment[];
60
+
61
+ @OneToMany(() => ExpenseTransaction, (expense) => expense.budget)
62
+ expenses?: ExpenseTransaction[];
63
+
64
+ @OneToMany(() => Income, (income) => income.budget)
65
+ incomes?: Income[];
58
66
  }
@@ -0,0 +1,68 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ OneToMany,
7
+ JoinColumn,
8
+ ObjectLiteral,
9
+ Index,
10
+ CreateDateColumn,
11
+ UpdateDateColumn,
12
+ } from "typeorm";
13
+ import { CropLot } from "./CropLot";
14
+ import { CropActivityType } from "../../types/CropActivityType";
15
+ import { UnitOfMeasure } from "../../entities/UnitOfMesure";
16
+ import { CropExpense } from "./CropExpense";
17
+
18
+ @Entity("crop_activities")
19
+ @Index(["cropLot", "activityDate"])
20
+ @Index(["activityType"])
21
+ export class CropActivity implements ObjectLiteral {
22
+ @PrimaryGeneratedColumn("increment")
23
+ idCropActivity!: number;
24
+
25
+ @ManyToOne(() => CropLot, (cropLot) => cropLot.activities, {
26
+ nullable: false,
27
+ onDelete: "CASCADE",
28
+ })
29
+ @JoinColumn({ name: "idCropLot" })
30
+ cropLot!: CropLot;
31
+
32
+ @Column({
33
+ type: "enum",
34
+ enum: CropActivityType,
35
+ })
36
+ activityType!: CropActivityType;
37
+
38
+ @Column("text", { nullable: false })
39
+ description!: string;
40
+
41
+ @Column("date", { nullable: false })
42
+ activityDate!: Date;
43
+
44
+ @Column("decimal", { precision: 12, scale: 4, nullable: true })
45
+ quantity?: number | null;
46
+
47
+ @ManyToOne(() => UnitOfMeasure, { nullable: true, onDelete: "SET NULL" })
48
+ @JoinColumn({ name: "idUnitOfMeasure" })
49
+ unitOfMeasure?: UnitOfMeasure | null;
50
+
51
+ @Column("decimal", { precision: 8, scale: 2, nullable: true })
52
+ laborHours?: number | null;
53
+
54
+ @Column("text", { nullable: true })
55
+ notes?: string | null;
56
+
57
+ @Column("varchar", { length: 255, nullable: true })
58
+ performedBy?: string | null;
59
+
60
+ @CreateDateColumn({ type: "timestamp" })
61
+ createdAt!: Date;
62
+
63
+ @UpdateDateColumn({ type: "timestamp" })
64
+ updatedAt!: Date;
65
+
66
+ @OneToMany(() => CropExpense, (expense) => expense.cropActivity, { cascade: true })
67
+ expenses?: CropExpense[];
68
+ }
@@ -0,0 +1,74 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ JoinColumn,
7
+ ObjectLiteral,
8
+ Index,
9
+ CreateDateColumn,
10
+ UpdateDateColumn,
11
+ } from "typeorm";
12
+ import { CropLot } from "./CropLot";
13
+ import { CropActivity } from "./CropActivity";
14
+ import { ExpenseType } from "../../entities/ExpenseType";
15
+ import { Resource } from "../apu/Resource";
16
+ import { Inventory } from "../../entities/Inventory";
17
+
18
+ @Entity("crop_expenses")
19
+ @Index(["cropLot", "expenseDate"])
20
+ @Index(["cropActivity"])
21
+ export class CropExpense implements ObjectLiteral {
22
+ @PrimaryGeneratedColumn("increment")
23
+ idCropExpense!: number;
24
+
25
+ @ManyToOne(() => CropLot, (cropLot) => cropLot.expenses, {
26
+ nullable: false,
27
+ onDelete: "CASCADE",
28
+ })
29
+ @JoinColumn({ name: "idCropLot" })
30
+ cropLot!: CropLot;
31
+
32
+ @ManyToOne(() => CropActivity, (activity) => activity.expenses, {
33
+ nullable: true,
34
+ onDelete: "SET NULL",
35
+ })
36
+ @JoinColumn({ name: "idCropActivity" })
37
+ cropActivity?: CropActivity | null;
38
+
39
+ @ManyToOne(() => ExpenseType, { nullable: true, onDelete: "SET NULL" })
40
+ @JoinColumn({ name: "idExpenseType" })
41
+ expenseType?: ExpenseType | null;
42
+
43
+ @Column("varchar", { length: 255, nullable: false })
44
+ concept!: string;
45
+
46
+ @Column("decimal", { precision: 14, scale: 2, nullable: false })
47
+ amount!: number;
48
+
49
+ @Column("decimal", { precision: 12, scale: 4, nullable: false, default: 1 })
50
+ quantity!: number;
51
+
52
+ @Column("decimal", { precision: 14, scale: 4, nullable: false })
53
+ unitPrice!: number;
54
+
55
+ @Column("date", { nullable: false })
56
+ expenseDate!: Date;
57
+
58
+ @ManyToOne(() => Resource, { nullable: true, onDelete: "SET NULL" })
59
+ @JoinColumn({ name: "idResource" })
60
+ resource?: Resource | null;
61
+
62
+ @ManyToOne(() => Inventory, { nullable: true, onDelete: "SET NULL" })
63
+ @JoinColumn({ name: "idInventory" })
64
+ inventory?: Inventory | null;
65
+
66
+ @Column("text", { nullable: true })
67
+ notes?: string | null;
68
+
69
+ @CreateDateColumn({ type: "timestamp" })
70
+ createdAt!: Date;
71
+
72
+ @UpdateDateColumn({ type: "timestamp" })
73
+ updatedAt!: Date;
74
+ }
@@ -0,0 +1,106 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ OneToMany,
7
+ JoinColumn,
8
+ ObjectLiteral,
9
+ Index,
10
+ CreateDateColumn,
11
+ UpdateDateColumn,
12
+ } from "typeorm";
13
+ import { GrowthArea } from "./GrowthArea";
14
+ import { ProductionSeason } from "./ProductionSeason";
15
+ import { PlantTechnicalSheet } from "../technical-sheet/PlantTechnicalSheet";
16
+ import { CropLotStatus } from "../../types/CropLotStatus";
17
+ import { CropStage } from "./CropStage";
18
+ import { CropActivity } from "./CropActivity";
19
+ import { CropExpense } from "./CropExpense";
20
+ import { Harvest } from "./Harvest";
21
+
22
+ @Entity("crop_lots")
23
+ @Index(["code"], { unique: true })
24
+ @Index(["growthArea"])
25
+ @Index(["season"])
26
+ @Index(["status"])
27
+ export class CropLot implements ObjectLiteral {
28
+ @PrimaryGeneratedColumn("increment")
29
+ idCropLot!: number;
30
+
31
+ @Column("varchar", { length: 64, nullable: false, unique: true })
32
+ code!: string;
33
+
34
+ @Column("varchar", { length: 255, nullable: false })
35
+ name!: string;
36
+
37
+ @ManyToOne(() => GrowthArea, (area) => area.cropLots, {
38
+ nullable: false,
39
+ onDelete: "RESTRICT",
40
+ })
41
+ @JoinColumn({ name: "idGrowthArea" })
42
+ growthArea!: GrowthArea;
43
+
44
+ @ManyToOne(() => ProductionSeason, (season) => season.cropLots, {
45
+ nullable: false,
46
+ onDelete: "RESTRICT",
47
+ })
48
+ @JoinColumn({ name: "idSeason" })
49
+ season!: ProductionSeason;
50
+
51
+ @ManyToOne(() => PlantTechnicalSheet, { nullable: true, onDelete: "SET NULL" })
52
+ @JoinColumn({ name: "idPlantTechnicalSheet" })
53
+ plantTechnicalSheet?: PlantTechnicalSheet | null;
54
+
55
+ @Column("decimal", { precision: 12, scale: 2, nullable: false, default: 0 })
56
+ quantity!: number;
57
+
58
+ @Column("decimal", { precision: 12, scale: 2, nullable: true })
59
+ expectedYield?: number | null;
60
+
61
+ @Column("decimal", { precision: 12, scale: 2, nullable: true })
62
+ actualYield?: number | null;
63
+
64
+ @Column("decimal", { precision: 14, scale: 4, nullable: true })
65
+ unitCost?: number | null;
66
+
67
+ @Column("decimal", { precision: 14, scale: 2, nullable: true })
68
+ totalCost?: number | null;
69
+
70
+ @Column({
71
+ type: "enum",
72
+ enum: CropLotStatus,
73
+ default: CropLotStatus.PLANNED,
74
+ })
75
+ status!: CropLotStatus;
76
+
77
+ @Column("date", { nullable: false })
78
+ sowingDate!: Date;
79
+
80
+ @Column("date", { nullable: true })
81
+ expectedHarvestDate?: Date | null;
82
+
83
+ @Column("date", { nullable: true })
84
+ actualHarvestDate?: Date | null;
85
+
86
+ @Column("text", { nullable: true })
87
+ notes?: string | null;
88
+
89
+ @CreateDateColumn({ type: "timestamp" })
90
+ createdAt!: Date;
91
+
92
+ @UpdateDateColumn({ type: "timestamp" })
93
+ updatedAt!: Date;
94
+
95
+ @OneToMany(() => CropStage, (stage) => stage.cropLot, { cascade: true })
96
+ stages?: CropStage[];
97
+
98
+ @OneToMany(() => CropActivity, (activity) => activity.cropLot, { cascade: true })
99
+ activities?: CropActivity[];
100
+
101
+ @OneToMany(() => CropExpense, (expense) => expense.cropLot, { cascade: true })
102
+ expenses?: CropExpense[];
103
+
104
+ @OneToMany(() => Harvest, (harvest) => harvest.cropLot, { cascade: true })
105
+ harvests?: Harvest[];
106
+ }
@@ -0,0 +1,45 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ OneToMany,
7
+ JoinColumn,
8
+ ObjectLiteral,
9
+ Index,
10
+ } from "typeorm";
11
+ import { CropLot } from "./CropLot";
12
+ import { GrowthStage } from "../../types/GrowthStage";
13
+ import { CropStageImage } from "./CropStageImage";
14
+
15
+ @Entity("crop_stages")
16
+ @Index(["cropLot", "stage"])
17
+ export class CropStage implements ObjectLiteral {
18
+ @PrimaryGeneratedColumn("increment")
19
+ idCropStage!: number;
20
+
21
+ @ManyToOne(() => CropLot, (cropLot) => cropLot.stages, {
22
+ nullable: false,
23
+ onDelete: "CASCADE",
24
+ })
25
+ @JoinColumn({ name: "idCropLot" })
26
+ cropLot!: CropLot;
27
+
28
+ @Column({
29
+ type: "enum",
30
+ enum: GrowthStage,
31
+ })
32
+ stage!: GrowthStage;
33
+
34
+ @Column("date", { nullable: false })
35
+ startDate!: Date;
36
+
37
+ @Column("date", { nullable: true })
38
+ endDate?: Date | null;
39
+
40
+ @Column("text", { nullable: true })
41
+ notes?: string | null;
42
+
43
+ @OneToMany(() => CropStageImage, (image) => image.cropStage, { cascade: true })
44
+ images?: CropStageImage[];
45
+ }
@@ -0,0 +1,32 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ JoinColumn,
7
+ ObjectLiteral,
8
+ CreateDateColumn,
9
+ } from "typeorm";
10
+ import { CropStage } from "./CropStage";
11
+
12
+ @Entity("crop_stage_images")
13
+ export class CropStageImage implements ObjectLiteral {
14
+ @PrimaryGeneratedColumn("increment")
15
+ idCropStageImage!: number;
16
+
17
+ @ManyToOne(() => CropStage, (stage) => stage.images, {
18
+ nullable: false,
19
+ onDelete: "CASCADE",
20
+ })
21
+ @JoinColumn({ name: "idCropStage" })
22
+ cropStage!: CropStage;
23
+
24
+ @Column("varchar", { length: 512, nullable: false })
25
+ imageUrl!: string;
26
+
27
+ @Column("varchar", { length: 255, nullable: true })
28
+ caption?: string | null;
29
+
30
+ @CreateDateColumn({ type: "timestamp" })
31
+ createdAt!: Date;
32
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ Entity,
3
+ PrimaryGeneratedColumn,
4
+ Column,
5
+ ManyToOne,
6
+ OneToMany,
7
+ JoinColumn,
8
+ ObjectLiteral,
9
+ Index,
10
+ } from "typeorm";
11
+ import { Branch } from "../../entities/Branches";
12
+ import { CropLot } from "./CropLot";
13
+
14
+ @Entity("growth_areas")
15
+ @Index(["code"], { unique: true })
16
+ export class GrowthArea implements ObjectLiteral {
17
+ @PrimaryGeneratedColumn("increment")
18
+ idGrowthArea!: number;
19
+
20
+ @Column("varchar", { length: 255, nullable: false })
21
+ name!: string;
22
+
23
+ @Column("varchar", { length: 64, nullable: false, unique: true })
24
+ code!: string;
25
+
26
+ @Column("text", { nullable: true })
27
+ description?: string | null;
28
+
29
+ @Column("decimal", { precision: 10, scale: 2, nullable: true })
30
+ capacity?: number | null;
31
+
32
+ @ManyToOne(() => Branch, { nullable: true, onDelete: "SET NULL" })
33
+ @JoinColumn({ name: "idBranch" })
34
+ branch?: Branch | null;
35
+
36
+ @Column("boolean", { default: true })
37
+ isActive!: boolean;
38
+
39
+ @OneToMany(() => CropLot, (cropLot) => cropLot.growthArea)
40
+ cropLots?: CropLot[];
41
+ }