add customer name, service info, second pickup location, and structured address fields to deliveries
This commit is contained in:
@@ -7,11 +7,20 @@ interface BackendDelivery {
|
||||
id: string;
|
||||
date: string; // YYYY-MM-DD from pgtype.Date
|
||||
pickup_location: PickupLocation;
|
||||
pickup_location_2: PickupLocation | null;
|
||||
product_name: string;
|
||||
product_name_2: string | null;
|
||||
customer_name: string;
|
||||
address: string;
|
||||
street: string;
|
||||
house: string;
|
||||
apartment: string | null;
|
||||
entrance: string | null;
|
||||
floor: string | null;
|
||||
phone: string;
|
||||
additional_phone: string | null;
|
||||
has_elevator: boolean;
|
||||
service_info: string | null;
|
||||
comment: string;
|
||||
status: DeliveryStatus;
|
||||
created_at: string; // ISO timestamp
|
||||
@@ -51,11 +60,20 @@ function mapBackendToFrontend(backend: BackendDelivery): Delivery {
|
||||
id: backend.id,
|
||||
date: backendDateToFrontend(backend.date),
|
||||
pickupLocation: backend.pickup_location,
|
||||
pickupLocation2: backend.pickup_location_2 || undefined,
|
||||
productName: backend.product_name,
|
||||
productName2: backend.product_name_2 || undefined,
|
||||
customerName: backend.customer_name,
|
||||
address: backend.address,
|
||||
street: backend.street,
|
||||
house: backend.house,
|
||||
apartment: backend.apartment || undefined,
|
||||
entrance: backend.entrance || undefined,
|
||||
floor: backend.floor || undefined,
|
||||
phone: backend.phone,
|
||||
additionalPhone: backend.additional_phone || undefined,
|
||||
hasElevator: backend.has_elevator,
|
||||
serviceInfo: backend.service_info || undefined,
|
||||
comment: backend.comment,
|
||||
status: backend.status,
|
||||
createdAt: new Date(backend.created_at).getTime(),
|
||||
@@ -96,11 +114,20 @@ export const deliveriesApi = {
|
||||
const payload = {
|
||||
date: data.date,
|
||||
pickup_location: data.pickupLocation,
|
||||
pickup_location_2: data.pickupLocation2 || null,
|
||||
product_name: data.productName,
|
||||
product_name_2: data.productName2 || null,
|
||||
customer_name: data.customerName,
|
||||
address: data.address,
|
||||
street: data.street,
|
||||
house: data.house,
|
||||
apartment: data.apartment || null,
|
||||
entrance: data.entrance || null,
|
||||
floor: data.floor || null,
|
||||
phone: data.phone,
|
||||
additional_phone: data.additionalPhone || '',
|
||||
additional_phone: data.additionalPhone || null,
|
||||
has_elevator: data.hasElevator,
|
||||
service_info: data.serviceInfo || null,
|
||||
comment: data.comment,
|
||||
};
|
||||
const response = await api.post<CreateDeliveryResponse>('/api/deliveries', payload);
|
||||
@@ -115,11 +142,20 @@ export const deliveriesApi = {
|
||||
const payload = {
|
||||
date: data.date,
|
||||
pickup_location: data.pickupLocation,
|
||||
pickup_location_2: data.pickupLocation2 || null,
|
||||
product_name: data.productName,
|
||||
product_name_2: data.productName2 || null,
|
||||
customer_name: data.customerName,
|
||||
address: data.address,
|
||||
street: data.street,
|
||||
house: data.house,
|
||||
apartment: data.apartment || null,
|
||||
entrance: data.entrance || null,
|
||||
floor: data.floor || null,
|
||||
phone: data.phone,
|
||||
additional_phone: data.additionalPhone || '',
|
||||
additional_phone: data.additionalPhone || null,
|
||||
has_elevator: data.hasElevator,
|
||||
service_info: data.serviceInfo || null,
|
||||
comment: data.comment,
|
||||
};
|
||||
await api.patch<UpdateDeliveryResponse>(`/api/deliveries/${id}`, payload);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { memo } from 'react';
|
||||
import { MapPin, Phone, Package, Store, Calendar, MessageSquare, CheckCircle2, Circle, CheckSquare } from 'lucide-react';
|
||||
import { MapPin, Phone, Package, Store, Calendar, MessageSquare, CheckCircle2, Circle, CheckSquare, User, Wrench } from 'lucide-react';
|
||||
import type { Delivery } from '../../types';
|
||||
import { pickupLocationLabels } from '../../types';
|
||||
import { StatusBadge } from './StatusBadge';
|
||||
import { Card } from '../ui/Card';
|
||||
|
||||
const CITY = 'kokshetau';
|
||||
|
||||
interface DeliveryCardProps {
|
||||
delivery: Delivery;
|
||||
onStatusChange: (id: string) => void;
|
||||
@@ -15,7 +17,7 @@ interface DeliveryCardProps {
|
||||
export const DeliveryCard = memo(({ delivery, onStatusChange, onEdit, onDelete }: DeliveryCardProps) => {
|
||||
const handleAddressClick = () => {
|
||||
const encodedAddress = encodeURIComponent(delivery.address);
|
||||
window.open(`https://maps.google.com/?q=${encodedAddress}`, '_blank');
|
||||
window.open(`https://2gis.kz/${CITY}/search/${encodedAddress}`, '_blank');
|
||||
};
|
||||
|
||||
const handlePhoneClick = () => {
|
||||
@@ -56,10 +58,20 @@ export const DeliveryCard = memo(({ delivery, onStatusChange, onEdit, onDelete }
|
||||
<span className="text-[#1b1b1d] font-medium">{delivery.date}</span>
|
||||
</div>
|
||||
|
||||
{/* Pickup locations */}
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Store size={16} className="text-[#75777d]" />
|
||||
<span className="text-[#1b1b1d]">{pickupLocationLabels[delivery.pickupLocation]}</span>
|
||||
<span className="text-[#1b1b1d]">
|
||||
{delivery.pickupLocation2
|
||||
? `${pickupLocationLabels[delivery.pickupLocation]} + ${pickupLocationLabels[delivery.pickupLocation2]}`
|
||||
: pickupLocationLabels[delivery.pickupLocation]}
|
||||
</span>
|
||||
</div>
|
||||
{delivery.pickupLocation2 && delivery.productName2 && (
|
||||
<div className="flex items-start gap-2 text-sm pl-6">
|
||||
<span className="text-[#75777d] text-xs">Со 2-й точки: {delivery.productName2}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Package size={16} className="text-[#75777d]" />
|
||||
@@ -71,11 +83,25 @@ export const DeliveryCard = memo(({ delivery, onStatusChange, onEdit, onDelete }
|
||||
className="flex items-start gap-2 text-sm w-full text-left hover:bg-[#f5f3f5] -mx-1 px-1 py-0.5 rounded transition-colors"
|
||||
>
|
||||
<MapPin size={16} className="text-[#F28C28] mt-0.5 shrink-0" />
|
||||
<span className="text-[#1B263B] underline decoration-[#F28C28]/30 underline-offset-2">
|
||||
{delivery.address}
|
||||
</span>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-[#1B263B] underline decoration-[#F28C28]/30 underline-offset-2">
|
||||
ул. {delivery.street}, д. {delivery.house}{delivery.apartment ? `, кв. ${delivery.apartment}` : ''}
|
||||
</span>
|
||||
{(delivery.entrance || delivery.floor) && (
|
||||
<span className="text-[#75777d] text-xs">
|
||||
{delivery.entrance && `Подъезд ${delivery.entrance}`}
|
||||
{delivery.entrance && delivery.floor && ', '}
|
||||
{delivery.floor && `этаж ${delivery.floor}`}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<User size={16} className="text-[#75777d]" />
|
||||
<span className="text-[#1b1b1d]">{delivery.customerName}</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={handlePhoneClick}
|
||||
className="flex items-center gap-2 text-sm w-full text-left hover:bg-[#f5f3f5] -mx-1 px-1 py-0.5 rounded transition-colors"
|
||||
@@ -105,6 +131,13 @@ export const DeliveryCard = memo(({ delivery, onStatusChange, onEdit, onDelete }
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{delivery.serviceInfo && (
|
||||
<div className="flex items-start gap-2 text-sm">
|
||||
<Wrench size={16} className="text-[#F28C28] mt-0.5 shrink-0" />
|
||||
<span className="text-[#45474d]">{delivery.serviceInfo}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{delivery.comment && (
|
||||
<div className="flex items-start gap-2 text-sm">
|
||||
<MessageSquare size={16} className="text-[#75777d] mt-0.5 shrink-0" />
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
|
||||
import { Button, Input, Select, Modal } from '../ui';
|
||||
import { pickupOptions } from '../../constants/pickup';
|
||||
import { formatDateForInput, parseDateFromInput, getTodayFrontend } from '../../utils/date';
|
||||
import { parseAddress } from '../../utils/addressParser';
|
||||
import type { Delivery, PickupLocation, DeliveryStatus } from '../../types';
|
||||
|
||||
interface DeliveryFormProps {
|
||||
@@ -20,28 +21,49 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
|
||||
const [formData, setFormData] = useState({
|
||||
date: defaultDate || getTodayFrontend(),
|
||||
pickupLocation: 'warehouse' as PickupLocation,
|
||||
pickupLocation2: null as PickupLocation | null,
|
||||
productName: '',
|
||||
productName2: '',
|
||||
customerName: '',
|
||||
address: '',
|
||||
street: '',
|
||||
house: '',
|
||||
apartment: '',
|
||||
entrance: '',
|
||||
floor: '',
|
||||
phone: '',
|
||||
additionalPhone: '',
|
||||
hasElevator: false,
|
||||
serviceInfo: '',
|
||||
comment: '',
|
||||
status: 'new' as DeliveryStatus,
|
||||
});
|
||||
const [showSecondPickup, setShowSecondPickup] = useState(false);
|
||||
const [showAddressDetails, setShowAddressDetails] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialData) {
|
||||
setFormData({
|
||||
date: initialData.date,
|
||||
pickupLocation: initialData.pickupLocation,
|
||||
pickupLocation2: initialData.pickupLocation2 || null,
|
||||
productName: initialData.productName,
|
||||
productName2: initialData.productName2 || '',
|
||||
customerName: initialData.customerName,
|
||||
address: initialData.address,
|
||||
street: initialData.street,
|
||||
house: initialData.house,
|
||||
apartment: initialData.apartment || '',
|
||||
entrance: initialData.entrance || '',
|
||||
floor: initialData.floor || '',
|
||||
phone: initialData.phone,
|
||||
additionalPhone: initialData.additionalPhone || '',
|
||||
hasElevator: initialData.hasElevator,
|
||||
serviceInfo: initialData.serviceInfo || '',
|
||||
comment: initialData.comment,
|
||||
status: initialData.status,
|
||||
});
|
||||
setShowSecondPickup(!!initialData.pickupLocation2);
|
||||
} else if (defaultDate) {
|
||||
setFormData(prev => ({ ...prev, date: defaultDate }));
|
||||
}
|
||||
@@ -54,7 +76,7 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
|
||||
|
||||
const isPhoneValid = !formData.phone || validatePhone(formData.phone);
|
||||
const isAdditionalPhoneValid = !formData.additionalPhone || validatePhone(formData.additionalPhone);
|
||||
const isFormValid = formData.productName && formData.address && formData.phone && isPhoneValid;
|
||||
const isFormValid = formData.productName && formData.address && formData.phone && isPhoneValid && formData.customerName && formData.street && formData.house;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -65,14 +87,25 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
|
||||
setFormData({
|
||||
date: defaultDate || getTodayFrontend(),
|
||||
pickupLocation: 'warehouse',
|
||||
pickupLocation2: null,
|
||||
productName: '',
|
||||
productName2: '',
|
||||
customerName: '',
|
||||
address: '',
|
||||
street: '',
|
||||
house: '',
|
||||
apartment: '',
|
||||
entrance: '',
|
||||
floor: '',
|
||||
phone: '',
|
||||
additionalPhone: '',
|
||||
hasElevator: false,
|
||||
serviceInfo: '',
|
||||
comment: '',
|
||||
status: 'new',
|
||||
});
|
||||
setShowSecondPickup(false);
|
||||
setShowAddressDetails(false);
|
||||
}
|
||||
onClose();
|
||||
} catch {
|
||||
@@ -126,16 +159,106 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
|
||||
required
|
||||
/>
|
||||
|
||||
{/* Address with auto-parse */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-[#1b1b1d] mb-1">
|
||||
Адрес доставки
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.address}
|
||||
onChange={(e) => {
|
||||
const newAddress = e.target.value;
|
||||
const parsed = parseAddress(newAddress);
|
||||
setFormData({
|
||||
...formData,
|
||||
address: newAddress,
|
||||
street: parsed.street || formData.street,
|
||||
house: parsed.house || formData.house,
|
||||
apartment: parsed.apartment || formData.apartment,
|
||||
entrance: parsed.entrance || formData.entrance,
|
||||
floor: parsed.floor || formData.floor,
|
||||
});
|
||||
if (parsed.street || parsed.house) {
|
||||
setShowAddressDetails(true);
|
||||
}
|
||||
}}
|
||||
onBlur={() => setShowAddressDetails(true)}
|
||||
placeholder="ул. Абая, д. 15, кв. 45, подъезд 3, этаж 5"
|
||||
className="w-full px-3 py-2 bg-[#f5f3f5] border border-[#c5c6cd] rounded-md text-[#1b1b1d] focus:outline-none focus:ring-2 focus:ring-[#1B263B] focus:border-transparent transition-colors"
|
||||
required
|
||||
/>
|
||||
<p className="text-xs text-[#75777d] mt-1">
|
||||
Улица, дом, квартира, подъезд, этаж
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Parsed address details */}
|
||||
{showAddressDetails && (
|
||||
<div className="bg-[#f5f3f5] rounded-lg p-4 space-y-3">
|
||||
<p className="text-sm font-medium text-[#1b1b1d]">Проверьте распознанные данные:</p>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs text-[#75777d] mb-1">Улица *</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.street}
|
||||
onChange={(e) => setFormData({ ...formData, street: e.target.value })}
|
||||
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs text-[#75777d] mb-1">Дом *</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.house}
|
||||
onChange={(e) => setFormData({ ...formData, house: e.target.value })}
|
||||
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs text-[#75777d] mb-1">Квартира</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.apartment}
|
||||
onChange={(e) => setFormData({ ...formData, apartment: e.target.value })}
|
||||
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs text-[#75777d] mb-1">Подъезд</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.entrance}
|
||||
onChange={(e) => setFormData({ ...formData, entrance: e.target.value })}
|
||||
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs text-[#75777d] mb-1">Этаж</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.floor}
|
||||
onChange={(e) => setFormData({ ...formData, floor: e.target.value })}
|
||||
className="w-full px-2 py-1.5 bg-white border border-[#c5c6cd] rounded text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Input
|
||||
label="Адрес разгрузки"
|
||||
value={formData.address}
|
||||
onChange={(e) => setFormData({ ...formData, address: e.target.value })}
|
||||
placeholder="ул. Примерная, д. 1"
|
||||
label="ФИО клиента *"
|
||||
value={formData.customerName}
|
||||
onChange={(e) => setFormData({ ...formData, customerName: e.target.value })}
|
||||
placeholder="Иванов Иван Иванович"
|
||||
required
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Телефон покупателя"
|
||||
label="Телефон покупателя *"
|
||||
type="tel"
|
||||
value={formData.phone}
|
||||
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
|
||||
@@ -175,6 +298,43 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Second pickup location */}
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="hasSecondPickup"
|
||||
checked={showSecondPickup}
|
||||
onChange={(e) => {
|
||||
setShowSecondPickup(e.target.checked);
|
||||
if (!e.target.checked) {
|
||||
setFormData({ ...formData, pickupLocation2: null, productName2: '' });
|
||||
}
|
||||
}}
|
||||
className="w-4 h-4 text-[#1B263B] border-[#c5c6cd] rounded focus:ring-[#1B263B]"
|
||||
/>
|
||||
<label htmlFor="hasSecondPickup" className="text-sm text-[#1b1b1d]">
|
||||
Добавить вторую точку загрузки
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{showSecondPickup && (
|
||||
<div className="bg-[#f5f3f5] rounded-lg p-4 space-y-3">
|
||||
<p className="text-sm font-medium text-[#1b1b1d]">Вторая точка загрузки</p>
|
||||
<Select
|
||||
label="Место загрузки 2"
|
||||
value={formData.pickupLocation2 || ''}
|
||||
onChange={(e) => setFormData({ ...formData, pickupLocation2: e.target.value as PickupLocation })}
|
||||
options={pickupOptions}
|
||||
/>
|
||||
<Input
|
||||
label="Что забрать со второй точки"
|
||||
value={formData.productName2}
|
||||
onChange={(e) => setFormData({ ...formData, productName2: e.target.value })}
|
||||
placeholder="Название товара со второй точки"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -188,6 +348,13 @@ export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDa
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Услуги (сборка, подъём)"
|
||||
value={formData.serviceInfo}
|
||||
onChange={(e) => setFormData({ ...formData, serviceInfo: e.target.value })}
|
||||
placeholder="Сборка 5000 тг, подъём на этаж 3000 тг"
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Комментарий"
|
||||
value={formData.comment}
|
||||
|
||||
@@ -114,6 +114,7 @@ export const DeliveryList = ({ deliveries, onStatusChange, onEdit, onDelete, onA
|
||||
<th className="px-4 py-3">Дата</th>
|
||||
<th className="px-4 py-3">Загрузка</th>
|
||||
<th className="px-4 py-3">Товар</th>
|
||||
<th className="px-4 py-3">Клиент</th>
|
||||
<th className="px-4 py-3">Адрес</th>
|
||||
<th className="px-4 py-3">Телефон</th>
|
||||
<th className="px-4 py-3">Комментарий</th>
|
||||
|
||||
@@ -4,6 +4,8 @@ import type { Delivery } from '../../types';
|
||||
import { pickupLocationLabels } from '../../types';
|
||||
import { StatusBadge } from './StatusBadge';
|
||||
|
||||
const CITY = 'kokshetau';
|
||||
|
||||
interface DeliveryRowProps {
|
||||
delivery: Delivery;
|
||||
onStatusChange: (id: string) => void;
|
||||
@@ -15,7 +17,7 @@ export const DeliveryRow = memo(({ delivery, onStatusChange, onEdit, onDelete }:
|
||||
const handleAddressClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
const encodedAddress = encodeURIComponent(delivery.address);
|
||||
window.open(`https://maps.google.com/?q=${encodedAddress}`, '_blank');
|
||||
window.open(`https://2gis.kz/${CITY}/search/${encodedAddress}`, '_blank');
|
||||
};
|
||||
|
||||
const handlePhoneClick = (e: React.MouseEvent) => {
|
||||
@@ -33,15 +35,25 @@ export const DeliveryRow = memo(({ delivery, onStatusChange, onEdit, onDelete }:
|
||||
/>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{delivery.date}</td>
|
||||
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{pickupLocationLabels[delivery.pickupLocation]}</td>
|
||||
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{delivery.productName}</td>
|
||||
<td className="px-4 py-3 text-sm text-[#1b1b1d]">
|
||||
{delivery.pickupLocation2
|
||||
? `${pickupLocationLabels[delivery.pickupLocation]} + ${pickupLocationLabels[delivery.pickupLocation2]}`
|
||||
: pickupLocationLabels[delivery.pickupLocation]}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-sm text-[#1b1b1d]">
|
||||
{delivery.productName}
|
||||
{delivery.productName2 && <span className="block text-xs text-[#75777d]">+ {delivery.productName2}</span>}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{delivery.customerName}</td>
|
||||
<td className="px-4 py-3">
|
||||
<button
|
||||
onClick={handleAddressClick}
|
||||
className="flex items-center gap-1.5 text-sm text-[#1B263B] hover:text-[#F28C28] transition-colors text-left"
|
||||
>
|
||||
<MapPin size={14} />
|
||||
<span className="max-w-[200px] truncate">{delivery.address}</span>
|
||||
<span className="max-w-[200px] truncate">
|
||||
ул. {delivery.street}, д. {delivery.house}{delivery.apartment ? `, кв. ${delivery.apartment}` : ''}
|
||||
</span>
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-4 py-3">
|
||||
|
||||
@@ -46,7 +46,7 @@ const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
};
|
||||
|
||||
const printDeliveries = (date: Date, dayDeliveries: Delivery[]) => {
|
||||
|
||||
|
||||
const printWindow = window.open('', '_blank');
|
||||
if (!printWindow) return;
|
||||
|
||||
@@ -58,31 +58,35 @@ const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
<style>
|
||||
body { font-family: system-ui, sans-serif; margin: 20px; }
|
||||
h1 { font-size: 18px; margin-bottom: 16px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { text-align: left; padding: 8px; border-bottom: 1px solid #ddd; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
th, td { text-align: left; padding: 6px; border-bottom: 1px solid #ddd; }
|
||||
th { font-weight: 600; background: #f5f5f5; }
|
||||
.status-new { background: #ffdcc3; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
|
||||
.status-delivered { background: #dcfce7; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
|
||||
.address-details { font-size: 11px; color: #666; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Доставки на ${format(date, 'dd MMMM yyyy', { locale: ru })}</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Статус</th>
|
||||
<th>Загрузка</th>
|
||||
<th>Товар</th>
|
||||
<th>Клиент</th>
|
||||
<th>Адрес</th>
|
||||
<th>Телефон</th>
|
||||
<th>Услуги</th>
|
||||
<th>Комментарий</th>
|
||||
</tr>
|
||||
${dayDeliveries.map((d: Delivery) => `
|
||||
<tr>
|
||||
<td><span class="status-${d.status}">${d.status === 'new' ? 'Новое' : 'Доставлено'}</span></td>
|
||||
<td>${pickupLocationLabels[d.pickupLocation]}</td>
|
||||
<td>${d.productName}</td>
|
||||
<td>${d.address}</td>
|
||||
<td>${d.pickupLocation2 ? pickupLocationLabels[d.pickupLocation] + ' + ' + pickupLocationLabels[d.pickupLocation2] : pickupLocationLabels[d.pickupLocation]}</td>
|
||||
<td>${d.productName}${d.productName2 ? '<br><small>+ ' + d.productName2 + '</small>' : ''}</td>
|
||||
<td>${d.customerName}</td>
|
||||
<td>
|
||||
ул. ${d.street}, д. ${d.house}${d.apartment ? ', кв. ' + d.apartment : ''}
|
||||
${d.entrance || d.floor ? '<br><span class="address-details">' + (d.entrance ? 'Подъезд ' + d.entrance : '') + (d.entrance && d.floor ? ', ' : '') + (d.floor ? 'этаж ' + d.floor : '') + '</span>' : ''}
|
||||
</td>
|
||||
<td>${d.phone}</td>
|
||||
<td>${d.serviceInfo || '-'}</td>
|
||||
<td>${d.comment || '-'}</td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
@@ -90,7 +94,7 @@ const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
|
||||
printWindow.document.write(html);
|
||||
printWindow.document.close();
|
||||
printWindow?.print();
|
||||
|
||||
@@ -5,10 +5,19 @@ export interface Delivery {
|
||||
id: string;
|
||||
date: string; // DD-MM-YYYY
|
||||
pickupLocation: PickupLocation;
|
||||
pickupLocation2?: PickupLocation | null;
|
||||
productName: string;
|
||||
address: string;
|
||||
productName2?: string | null;
|
||||
customerName: string;
|
||||
phone: string;
|
||||
additionalPhone?: string;
|
||||
address: string; // full address for compatibility
|
||||
street: string;
|
||||
house: string;
|
||||
apartment?: string;
|
||||
entrance?: string;
|
||||
floor?: string;
|
||||
serviceInfo?: string;
|
||||
hasElevator: boolean;
|
||||
comment: string;
|
||||
status: DeliveryStatus;
|
||||
@@ -29,7 +38,6 @@ export const statusLabels: Record<DeliveryStatus, string> = {
|
||||
delivered: 'Доставлено',
|
||||
};
|
||||
|
||||
// Auth types
|
||||
export interface LoginRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
122
frontend/src/utils/addressParser.ts
Normal file
122
frontend/src/utils/addressParser.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
export interface ParsedAddress {
|
||||
street: string;
|
||||
house: string;
|
||||
apartment: string;
|
||||
entrance: string;
|
||||
floor: string;
|
||||
remaining: string; // unrecognized parts
|
||||
}
|
||||
|
||||
// Common Russian/Kazakh address patterns
|
||||
const STREET_PREFIXES = ['ул\\.', 'ул', 'пр\\.', 'пр', 'пр-т', 'бульвар', 'пер\\.', 'пер', 'ш\\.', 'шоссе', 'тракт'];
|
||||
const HOUSE_PATTERNS = ['д\\.', 'дом', 'д(?=\\s*\\d)', 'строение', 'стр\\.'];
|
||||
const APARTMENT_PATTERNS = ['кв\\.', 'квартира', 'кв(?=\\s*\\d)', 'офис', 'оф\\.'];
|
||||
const ENTRANCE_PATTERNS = ['подъезд', 'под\\.', 'под(?=\\s*\\d)', 'п(?=\\s*\\d)'];
|
||||
const FLOOR_PATTERNS = ['этаж', 'эт\\.', 'эт(?=\\s*\\d)', 'э(?=\\s*\\d)'];
|
||||
|
||||
function createPattern(prefixes: string[]): RegExp {
|
||||
const prefixPart = prefixes.join('|');
|
||||
// Match prefix followed by optional spaces/separators and then the value
|
||||
// Use Unicode property \p{L} for letters to support Cyrillic
|
||||
return new RegExp(`(?:${prefixPart})[\\s\\.]*([0-9]+[\\p{L}\\-]*|[\\p{L}][\\p{L}\\d\\-]*)`, 'iu');
|
||||
}
|
||||
|
||||
function extractValue(text: string, patterns: string[]): { value: string; remaining: string } {
|
||||
const regex = createPattern(patterns);
|
||||
const match = text.match(regex);
|
||||
if (match) {
|
||||
// Remove the matched part from text
|
||||
const remaining = text.replace(match[0], '').trim().replace(/^[,.\s]+/, '');
|
||||
return { value: match[1].trim(), remaining };
|
||||
}
|
||||
return { value: '', remaining: text };
|
||||
}
|
||||
|
||||
export function parseAddress(address: string): ParsedAddress {
|
||||
let remaining = address.trim();
|
||||
|
||||
// Extract components in order
|
||||
const streetResult = extractValue(remaining, STREET_PREFIXES);
|
||||
const street = streetResult.value;
|
||||
remaining = streetResult.remaining;
|
||||
|
||||
// Try to extract house: first standalone number at the start, then with prefix
|
||||
let house = '';
|
||||
let houseResult;
|
||||
|
||||
// Try standalone number first (e.g., "ул. Абая 5" - house is "5" without "д." prefix)
|
||||
const standaloneHouseMatch = remaining.match(/^\s*(\d+[\p{L}]?)(?:\s*[,;]|\s+(?=кв|под|э|п\s|э\s|д\.|д\s|дом))/iu);
|
||||
if (standaloneHouseMatch) {
|
||||
house = standaloneHouseMatch[1];
|
||||
remaining = remaining.slice(standaloneHouseMatch[0].length).trim().replace(/^[,;\s]+/, '');
|
||||
} else {
|
||||
// Fallback: try with prefix patterns
|
||||
houseResult = extractValue(remaining, HOUSE_PATTERNS);
|
||||
house = houseResult.value;
|
||||
remaining = houseResult.remaining;
|
||||
}
|
||||
|
||||
const apartmentResult = extractValue(remaining, APARTMENT_PATTERNS);
|
||||
const apartment = apartmentResult.value;
|
||||
remaining = apartmentResult.remaining;
|
||||
|
||||
const entranceResult = extractValue(remaining, ENTRANCE_PATTERNS);
|
||||
const entrance = entranceResult.value;
|
||||
remaining = entranceResult.remaining;
|
||||
|
||||
const floorResult = extractValue(remaining, FLOOR_PATTERNS);
|
||||
const floor = floorResult.value;
|
||||
remaining = floorResult.remaining;
|
||||
|
||||
// Clean up remaining - remove common separators
|
||||
remaining = remaining
|
||||
.replace(/^[,.\s]+/, '')
|
||||
.replace(/[,.\s]+$/, '')
|
||||
.trim();
|
||||
|
||||
return {
|
||||
street,
|
||||
house,
|
||||
apartment,
|
||||
entrance,
|
||||
floor,
|
||||
remaining
|
||||
};
|
||||
}
|
||||
|
||||
// Format address for display
|
||||
export function formatAddressShort(addr: ParsedAddress): string {
|
||||
const parts: string[] = [];
|
||||
if (addr.street) parts.push(addr.street);
|
||||
if (addr.house) parts.push(`д. ${addr.house}`);
|
||||
if (addr.apartment) parts.push(`кв. ${addr.apartment}`);
|
||||
return parts.join(', ') || addr.remaining;
|
||||
}
|
||||
|
||||
export function formatAddressDetails(addr: ParsedAddress): string {
|
||||
const parts: string[] = [];
|
||||
if (addr.entrance) parts.push(`Подъезд ${addr.entrance}`);
|
||||
if (addr.floor) parts.push(`этаж ${addr.floor}`);
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
// Build full address from components
|
||||
export function buildFullAddress(
|
||||
street: string,
|
||||
house: string,
|
||||
apartment?: string,
|
||||
entrance?: string,
|
||||
floor?: string
|
||||
): string {
|
||||
const parts: string[] = [];
|
||||
if (street) parts.push(street);
|
||||
if (house) parts.push(`д. ${house}`);
|
||||
if (apartment) parts.push(`кв. ${apartment}`);
|
||||
if (entrance || floor) {
|
||||
const details: string[] = [];
|
||||
if (entrance) details.push(`подъезд ${entrance}`);
|
||||
if (floor) details.push(`этаж ${floor}`);
|
||||
parts.push(details.join(', '));
|
||||
}
|
||||
return parts.join(', ');
|
||||
}
|
||||
Reference in New Issue
Block a user